public override void OnAwake() { base.OnAwake(); mountsLookup = transform.GetNestedComponentInParents <MountsLookup>(); defaultMountingMask = 1 << (defaultMounting.id); }
/// <summary> /// Ensure this gameobject has a NetObject with a MountsLookup component, as well as a "Root" Mount. Adds these if needed. /// </summary> /// <param name="go"></param> /// <returns></returns> public static MountsLookup EstablishMounts(GameObject go) { /// Must have a NetObj NetObject netObj = go.GetComponent <NetObject>(); if (!netObj) { netObj = go.GetComponentInParent <NetObject>(); } if (!netObj) { netObj = go.transform.root.gameObject.AddComponent <NetObject>(); } MountsLookup mountsLookup = netObj.transform.GetNestedComponentInChildren <MountsLookup>(); /// Remove Lookup if its somehow on a child if (mountsLookup && mountsLookup.gameObject != go) { Object.DestroyImmediate(mountsLookup); } /// Add Lookup if its still missing if (!mountsLookup) { mountsLookup = netObj.gameObject.AddComponent <MountsLookup>(); } /// Create or correct the root mount var rootMount = netObj.gameObject.GetComponent <Mount>(); if (rootMount == null) { rootMount = netObj.gameObject.gameObject.AddComponent <Mount>(); rootMount.mountType = new MountSelector(0); } else if (rootMount.mountType.id != 0) { rootMount.mountType.id = 0; } mountsLookup.CollectMounts(); return(mountsLookup); }
public override void OnAwake() { base.OnAwake(); syncTransform = GetComponent <SyncTransform>(); respawnStateInfo = new StateChangeInfo( respawnState, transform.parent ? transform.parent.GetComponent <Mount>() : null, transform.localPosition, transform.localEulerAngles, null, true); transform.GetNestedComponentsInChildren(onStateChangeCallbacks); transform.GetComponents(onTeleportCallbacks); mountsLookup = netObj.GetComponent <MountsLookup>(); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); thismount = target as Mount; var netObj = thismount.transform.GetComponentInParentEvenIfDisabled <NetObject>(); if (netObj == null) { Debug.LogWarning(thismount.name + " Mount is on a non-NetObject."); return; } usedIndexes.Clear(); MountsLookup mountslookup = netObj.GetComponent <MountsLookup>(); if (!mountslookup) { mountslookup = netObj.gameObject.AddComponent <MountsLookup>(); } mountslookup.CollectMounts(); //EditorGUI.BeginChangeCheck(); //EditorGUI.BeginChangeCheck(); EditorGUI.BeginDisabledGroup(thismount.componentIndex == 0); EditorGUILayout.PropertyField(serializedObject.FindProperty("mountType")); EditorGUI.EndDisabledGroup(); MountsLookup.DrawAllMountMappings(thismount, mountslookup); EditorGUILayout.Space(); MountSettings.Single.DrawGui(target, true, false, false, false); }
public static void DrawAllMountMappings(Mount thismount, MountsLookup mountsLookup) { EnsureStylesExists(); int usedmask = 0; int cnt = mountsLookup.indexedMounts.Count; EditorGUILayout.LabelField("All Mounts On NetObject", (GUIStyle)"BoldLabel"); /// Massive warning if too many mounts are on the object, and the last ones will not get serialized correctly. if (mountsLookup.indexedMounts.Count > MountSettings.mountTypeCount) { EditorGUILayout.HelpBox("NetObject has too many mounts. Mount count is limited to the count value in MountSettings.", MessageType.Error); } if (cnt > 0) { EditorGUILayout.BeginVertical((GUIStyle)"HelpBox"); for (int i = 0; i < mountsLookup.indexedMounts.Count; ++i) { SerializedObject mount = new SerializedObject(mountsLookup.indexedMounts[i]); var mountType = mount.FindProperty("mountType"); var index = mountType.FindPropertyRelative("id"); /// Make sure Root is selected for the first mount, and only the first mount if (i == 0) { if (index.intValue != 0) { index.intValue = 0; mount.ApplyModifiedProperties(); } } /// Switch off Root for all other mounts else if (index.intValue == 0) { index.intValue = i; mount.ApplyModifiedProperties(); Debug.LogWarning("Only the first root Mount on a NetOjbect can be set to mountType 'Root'"); } int idx = index.intValue; /// Watch for repeats int idxmask = 1 << idx; bool isAlreadyUsed = (idxmask & usedmask) != 0; usedmask |= idxmask; bool isthis = (ReferenceEquals(mount.targetObject, thismount)); const int CNT_WIDTH = 30; const int LABL_PAD = 2; /// Start drawing the row EditorGUILayout.BeginHorizontal(isthis ? mountHiliteStyle : mountNoliteStyle); /// Get the indented rect Rect indexrect = EditorGUILayout.GetControlRect(GUILayout.MaxWidth(CNT_WIDTH), GUILayout.MinWidth(CNT_WIDTH)); indexrect.xMin += 8; /// Warning Icon if (isAlreadyUsed) { EditorGUI.LabelField(new Rect(indexrect) { xMin = indexrect.xMin - 3 }, new GUIContent(EditorGUIUtility.FindTexture("CollabError"), "More than one Mount has the same compatible mount selection. Only the first will be used.")); } else { /// Index EditorGUI.BeginDisabledGroup(!isthis); EditorGUI.LabelField(indexrect, i.ToString(), mountlabelstyle); EditorGUI.EndDisabledGroup(); } /// Mount Selector float selectorWidth = EditorGUIUtility.labelWidth - (CNT_WIDTH + LABL_PAD + 8); EditorGUI.BeginDisabledGroup(i == 0); EditorGUILayout.PropertyField(mountType, GUIContent.none, GUILayout.MaxWidth(selectorWidth), GUILayout.MinWidth(selectorWidth)); EditorGUI.EndDisabledGroup(); if (isthis) { /// Object Rect thisrect = EditorGUILayout.GetControlRect(GUILayout.MinWidth(40)); thisrect.xMin += 16; EditorGUI.LabelField(thisrect, "This", mountlabelstyle); } else { EditorGUI.BeginDisabledGroup(!isthis); EditorGUILayout.ObjectField(mountsLookup.indexedMounts[i], typeof(Mount), false /*, GUILayout.MaxWidth(EditorGUIUtility.labelWidth - cntwidth), GUILayout.MinWidth(EditorGUIUtility.labelWidth - cntwidth)*/); EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); } }
public override void OnAwake() { base.OnAwake(); mountsLookup = netObj.GetComponent <MountsLookup>(); }
protected override void Reset() { base.Reset(); mountsLookup = MountsLookup.EstablishMounts(gameObject); //UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(this, (index == 0)); }