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

#if PUN_2_OR_NEWER
            MountsManager mountsLookup = netObj.transform.GetNestedComponentInChildren <MountsManager, NetObject>(true);
#else
            MountsManager mountsLookup = null;
#endif
            /// 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 <MountsManager>();
            }

            /// 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);
        }
Exemple #2
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

#if PUN_2_OR_NEWER
            thismount = target as Mount;

            var netObj = thismount.transform.GetParentComponent <NetObject>();

            if (netObj == null)
            {
                Debug.LogWarning(thismount.name + " Mount is on a non-NetObject.");
                return;
            }

            usedIndexes.Clear();

            MountsManager mountslookup = netObj.GetComponent <MountsManager>();
            if (!mountslookup)
            {
                mountslookup = netObj.gameObject.AddComponent <MountsManager>();
            }

            mountslookup.CollectMounts();

            //EditorGUI.BeginChangeCheck();

            //EditorGUI.BeginChangeCheck();
            EditorGUI.BeginDisabledGroup(thismount.componentIndex == 0);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("mountType"));
            EditorGUI.EndDisabledGroup();

            MountsManager.DrawAllMountMappings(thismount, mountslookup);

            EditorGUILayout.Space();
            MountSettings.Single.DrawGui(target, true, false, false, false);
#endif
        }