Kind of glossing over in and outs but here’s what I used as an editor script to look up a script in the inspector and recall values from an array for use in another script, to be fair, this would be only useful for making in house editor components or assets for others to use in the editor. but non the less:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
using UnityEngine; using System.Collections; using UnityEditor; //Good Unity Editor example of how to look up a built in array on another gameobject i.e. gemobjet[] prefab array //and use this as a drop down choice list for setting and int index on another script requiring reference //also a good way to use stylised list when property drawers are not complex enough [CustomEditor(typeof(ConnectorPrefab))] //type of inspector script you want to populate values off! [CanEditMultipleObjects] [System.Serializable] class ConnectorPrefabEditor : Editor { private ConfigPrefabStore cps; // ref to other script where to get values from public static bool isconfigured=false; public static string warning=""; public static string[] choices; private SerializedObject so; void OnEnable () { isconfigured=false; ConfigPrefabStore[] cpsa=(ConfigPrefabStore[])Resources.FindObjectsOfTypeAll(typeof(ConfigPrefabStore)) as ConfigPrefabStore[]; if (cpsa.Length>0) { cps=cpsa[0]; if (cps.PartPrefabs.Length>0) { choices=new string[cps.PartPrefabs.Length]; for(int i=0;i<cps.PartPrefabs.Length;++i) { choices[i]=cps.PartPrefabs[i].name; } isconfigured=true; } else { warning="Config Prefab Store Contains No Part Prefabs to link to! Please Add a part prefab!"; } } else { warning="Cannot find and instance of a Config Prefab Store within the Scene, Please add a Config Prefab Store Component to one of your root config GameObject"; } } public override void OnInspectorGUI() { if (isconfigured) { so=serializedObject; so.Update(); //EditorGUIUtility.LookLikeInspector(); //SerializedProperty cps = serializedObject.FindProperty ("ConnectableParts"); //EditorGUILayout.PropertyField(cps, true); ArrayGUI(so,"ConnectableParts"); //connectedprefabs = serializedObject.FindProperty ("ConnectablePrefabs"); so.ApplyModifiedProperties(); //EditorGUIUtility.LookLikeControls(); } else { //GUILayout.Label( warning , GUILayout.ExpandWidth(true)); GUIContent myLabel = new GUIContent("Warning![hover for details])", warning); EditorGUILayout.LabelField (myLabel); } } private void ArrayGUI(SerializedObject obj, string name) { int size = obj.FindProperty(name + ".Array.size").intValue; int newSize = EditorGUILayout.IntField("Prefab Choices Size", size); if (newSize != size) obj.FindProperty(name + ".Array.size").intValue = newSize; EditorGUI.indentLevel = 1; for (int i=0;i<newSize;i++) { EditorGUI.indentLevel = 1; EditorGUILayout.LabelField("Connectable Part "+i); EditorGUI.indentLevel = 3; SerializedProperty listProperty = obj.FindProperty(string.Format("{0}.Array.data[{1}]", name, i)); int selection=listProperty.FindPropertyRelative("PartID").intValue; EditorGUI.indentLevel = 2; EditorGUILayout.LabelField("Connectable Prefab:"); listProperty.FindPropertyRelative("PartID").intValue=EditorGUILayout.Popup(selection, choices); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Show Name:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("ShowName"), GUIContent.none); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Hide From User:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("HiddenFromChoice"), GUIContent.none); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("AutoConnected:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("AutoConnected"), GUIContent.none); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("SelectAutoConnected:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("SelectAutoConnected"), GUIContent.none); EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel = 3; // EditorGUILayout.LabelField("Anchor Effect:"); // EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("AnchorEffect"), GUIContent.none); EditorGUILayout.LabelField("Inherits Size:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("InheritInitialSize"), GUIContent.none); EditorGUILayout.LabelField("Keeps Size:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("InheritKeepSize"), GUIContent.none); EditorGUILayout.LabelField("Parent Shared Dimension:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("ParentShareSize"), GUIContent.none); EditorGUILayout.LabelField("Child Shared Dimension:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("ChildShareSize"), GUIContent.none); EditorGUILayout.LabelField("Inherit Parent Connections from:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("InheritConnectors"), GUIContent.none); EditorGUILayout.LabelField("InheritsParentSharedAttribute:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("InheritsParentSharedAttribute"), GUIContent.none); EditorGUILayout.LabelField("LocalOffset:"); EditorGUILayout.PropertyField(listProperty.FindPropertyRelative("LocalOffset"), GUIContent.none); EditorGUI.indentLevel = 2; EditorGUILayout.LabelField("Shared Attributes:"); SerializedProperty Sa=listProperty.FindPropertyRelative("SharedAttributes"); int SaSize = EditorGUILayout.IntField("Size", Sa.arraySize); if (SaSize!=Sa.arraySize) Sa.arraySize = SaSize; for (int j=0;j<Sa.arraySize;++j) { EditorGUI.indentLevel = 3; SerializedProperty element=Sa.GetArrayElementAtIndex(j); EditorGUILayout.LabelField("Dimension Affected:"); EditorGUILayout.PropertyField(element.FindPropertyRelative("DimensionAffected"), GUIContent.none); EditorGUILayout.LabelField("Dim Size Plus Minus:"); EditorGUILayout.PropertyField(element.FindPropertyRelative("DimensionPlusMinus"), GUIContent.none); EditorGUILayout.LabelField("Position Offset:"); EditorGUILayout.PropertyField(element.FindPropertyRelative("InitialDirPosOffset"), GUIContent.none); } } } |
You cannot cut and paste this script!!!!! It is for looking at the methodology…but it may help people who already now what there doing, to look up an array on another script and reflect the values in and inspector elsewhere.
Cheers Jon
7802 Total Views 5 Views Today