/// <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 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); }