Beispiel #1
0
        public override void OnAwakeInitialize(bool isNetObject)
        {
            base.OnAwakeInitialize(isNetObject);

            this.transform.EnsureRootComponentExists <ContactManager, NetObject>();

            mountsLookup        = netObj.transform.GetComponent <MountsManager>();
            defaultMountingMask = 1 << (defaultMounting.id);
        }
Beispiel #2
0
        public override void OnAwake()
        {
            base.OnAwake();

            iSpawnController = GetComponent <ISpawnController>();

            syncTransform = GetComponent <SyncTransform>();
            syncOwner     = GetComponent <SyncOwner>();

            transform.GetNestedComponentsInChildren <IOnStateChange, NetObject>(onStateChangeCallbacks);
            transform.GetComponents(flagTeleportCallbacks);

            mountsLookup = netObj.GetComponent <MountsManager>();
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
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
        }
Beispiel #5
0
 public override void OnAwake()
 {
     base.OnAwake();
     mountsLookup = netObj.GetComponent <MountsManager>();
 }
Beispiel #6
0
 protected override void Reset()
 {
     base.Reset();
     mountsLookup = MountsManager.EstablishMounts(gameObject);
     //UnityEditorInternal.InternalEditorUtility.SetIsInspectorExpanded(this, (index == 0));
 }
Beispiel #7
0
        public static void DrawAllMountMappings(Mount thismount, MountsManager 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();
            }
        }