Пример #1
0
        protected NetObject EnsureComponentsDependenciesExist()
        {
            if (!netObj)
            {
                netObj = GetComponentInParent <NetObject>();
            }

            if (netObj)
            {
#if PUN_2_OR_NEWER
                pv = netObj.GetComponent <PhotonView>();
#endif
                if (this is IContacting)
                {
                    if (ReferenceEquals(netObj.GetComponent <IContactTrigger>(), null))
                    {
                        netObj.gameObject.AddComponent <ContactTrigger>();
                    }
                }

                RigidbodyType = (netObj.Rb) ? RigidbodyType.RB : (netObj.Rb2D) ? RigidbodyType.RB2D : RigidbodyType.None;

                return(netObj);
            }
            else
            {
                Debug.LogError("NetComponent derived class cannot find a NetObject on '" + transform.root.name + "'.");
                return(null);
            }
        }
Пример #2
0
        protected virtual NetObject EnsureComponentsDependenciesExist()
        {
            if (!netObj)
            {
                netObj = transform.GetParentComponent <NetObject>();
            }

            if (netObj)
            {
                photonView = netObj.GetComponent <PhotonView>();

                //if (this is IContactSystem)
                //	if (ReferenceEquals(netObj.GetComponent<IContactTrigger>(), null))
                //		netObj.gameObject.AddComponent<ContactTrigger>();

                RigidbodyType = (netObj.Rb) ? RigidbodyType.RB : (netObj.Rb2D) ? RigidbodyType.RB2D : RigidbodyType.None;

                return(netObj);
            }
            else
            {
                Debug.LogError("NetComponent derived class cannot find a NetObject on '" + transform.root.name + "'.");
                return(null);
            }
        }
Пример #3
0
        /// <summary>
        /// Be sure to use base.OnAwake() when overriding.
        /// This is called when the NetObject runs Awake(). All code that depends on the NetObj being initialized should use this
        /// rather than Awake();
        /// </summary>
        public virtual void OnAwake()
        {
            netObj = GetComponentInParent <NetObject>();

            if (netObj)
            {
                syncState = netObj.GetComponent <SyncState>();
            }

            EnsureComponentsDependenciesExist();

            OnAwakeInitialize(true);
        }
Пример #4
0
        public override void OnInspectorGUI()
        {
            myTarget = (NetObject)target;

            serializedObject.Update();
            generateTitle("uMMO SoftRare.Net.NetObject", "Configure specifics about this networked game object here (being refered to as 'this NetObject'). Move the mouse over a property of this script to read information about its uses and limitations.", EditorStyles.toolbar);

            EditorGUILayout.PropertyField(objectType);
            generateTitle("Synchronization Methods", "Define here how you want transforms and animations synchronized");

            EditorGUILayout.PropertyField(transformSyncingMethod);
            if (myTarget.transformSyncingMethod == SyncingMethod.SyncUsing_DEFAULT_NATIVE_COMPONENT)
            {
                if (myTarget.GetComponent <NetworkTransform>() == null)
                {
                    myTarget.gameObject.AddComponent <NetworkTransform>();
                }
                else
                {
                    myTarget.gameObject.GetComponent <NetworkTransform>().enabled = true;
                }
            }
            else if (myTarget.transformSyncingMethod != SyncingMethod.SyncUsing_DEFAULT_NATIVE_COMPONENT)
            {
                if (myTarget.GetComponent <NetworkTransform>() != null)
                {
                    myTarget.gameObject.GetComponent <NetworkTransform>().enabled = false;
                }
            }
            if (myTarget.transformSyncingMethod == SyncingMethod.SyncUsing_DEFAULT_uMMO_PLUGIN)
            {
                EditorGUILayout.PropertyField(pluginShouldSyncPosition);
                EditorGUILayout.PropertyField(pluginShouldSyncRotation);
            }

            EditorGUILayout.PropertyField(animationSyncingMethod);
            bool     usesMecanim = false;
            Animator animator    = myTarget.gameObject.GetComponentInChildren <Animator>();

            if (animator != null)
            {
                usesMecanim = true;
            }

            if (myTarget.animationSyncingMethod == SyncingMethod.SyncUsing_DEFAULT_NATIVE_COMPONENT)
            {
                if (usesMecanim)
                {
                    if (myTarget.gameObject.GetComponent <NetworkAnimator>() == null)
                    {
                        myTarget.gameObject.AddComponent <NetworkAnimator>();

                        myTarget.gameObject.GetComponent <NetworkAnimator>().enabled = true;
                    }

                    //myTarget.gameObject.GetComponent<NetworkAnimator>().animator = animator; //throws error
                }
            }
            else if (myTarget.animationSyncingMethod != SyncingMethod.SyncUsing_DEFAULT_NATIVE_COMPONENT)
            {
                if (myTarget.GetComponent <NetworkAnimator>() != null)
                {
                    myTarget.gameObject.GetComponent <NetworkAnimator>().enabled = false;
                }
            }
            EditorGUI.indentLevel += 1;
            if (myTarget.animationSyncingMethod == SyncingMethod.SyncUsing_DEFAULT_uMMO_PLUGIN)
            {
                EditorGUILayout.PropertyField(pluginShouldSyncAnimations);
            }
            if (myTarget.animationSyncingMethod == SyncingMethod.SyncUsing_DEFAULT_uMMO_PLUGIN)
            {
                if (usesMecanim && myTarget.pluginShouldSyncAnimations)
                {
                    var controller = animator.runtimeAnimatorController as AnimatorController;
                    if (controller != null)
                    {
                        EditorGUI.indentLevel += 1;
                        for (int i = 0; i < controller.parameters.Length; i++) // (var p in controller.parameters) {
                        {
                            AnimatorControllerParameter acp = controller.parameters[i];

                            bool oldExists = GetArrayElementAtIndex(mecanimVarsToSync, i) >= 0 ? true: false;
                            bool newExists = EditorGUILayout.Toggle(acp.name, oldExists);
                            if (newExists != oldExists)
                            {
                                if (newExists)
                                {
                                    addToStringArr(mecanimVarsToSync, i);
                                }
                                else
                                {
                                    removeFromStringArr(mecanimVarsToSync, i);
                                }
                                EditorUtility.SetDirty(target);
                            }
                        }
                        EditorGUI.indentLevel -= 1;
                    }
                }
            }

            EditorGUI.indentLevel -= 1;
            generateTitle("Spawn Case Settings", "Drag and drop scripts from this gameobject to handle different spawn cases per script");
            EditorGUILayout.PropertyField(handelScriptsBasedOnSpawnCase, true);
            EditorGUI.indentLevel += 1;
            if (myTarget.handelScriptsBasedOnSpawnCase)
            {
                if (myTarget.objectType == ObjectType.Player)
                {
                    EditorGUILayout.PropertyField(clientLocalPlayerScripts, true);
                    EditorGUILayout.PropertyField(clientRemotePlayerScripts, true);
                    EditorGUILayout.PropertyField(serverPlayerScripts, true);
                }
                else if (myTarget.objectType == ObjectType.NonPlayerObject)
                {
                    EditorGUILayout.PropertyField(serverNPOScripts, true);
                    EditorGUILayout.PropertyField(clientNPOScripts, true);
                }
            }
            EditorGUI.indentLevel -= 1;

            EditorGUILayout.PropertyField(handelScriptsBasedOnSpawnCaseAtRuntime, true);
            EditorGUI.indentLevel += 1;
            if (myTarget.handelScriptsBasedOnSpawnCaseAtRuntime)
            {
                if (myTarget.objectType == ObjectType.Player)
                {
                    EditorGUILayout.PropertyField(clientLocalPlayerRuntimeScripts, true);
                    EditorGUILayout.PropertyField(clientRemotePlayerRuntimeScripts, true);
                    EditorGUILayout.PropertyField(serverPlayerRuntimeScripts, true);
                }
                else if (myTarget.objectType == ObjectType.NonPlayerObject)
                {
                    EditorGUILayout.PropertyField(serverNPORuntimeScripts, true);
                    EditorGUILayout.PropertyField(clientNPORuntimeScripts, true);
                }
            }
            EditorGUI.indentLevel -= 1;

            generateTitle("Input Settings", "Define here how you want input synchonized and processed. Especially important for cases of server-authority");
            if (myTarget.GetComponent <NetworkIdentity>() != null && !myTarget.GetComponent <NetworkIdentity>().localPlayerAuthority&& myTarget.objectType == ObjectType.Player)
            {
                //settings for authoritative server:
                EditorGUILayout.PropertyField(inputCollectionMethod, true);

                if (myTarget.inputCollectionMethod == InputCollectionMethod.CollectEveryFrame)
                {
                    EditorGUI.indentLevel += 1;
                    strings2enumView(inputFromAxesToSendToServer, "Input Axes");
                    EditorGUILayout.PropertyField(inputFromKeysToSendToServer, true);
                    EditorGUILayout.PropertyField(inputFromMouseButtonsToSendToServer, true);
                    EditorGUI.indentLevel -= 1;
                }

                EditorGUILayout.PropertyField(inputSendingMethod, true);
            }
            EditorGUILayout.PropertyField(inputReadingMethod, true);
            EditorGUILayout.PropertyField(clearInputStates, true);

            generateTitle("Plugins", "Drag and drop \"Messenger\" plugins here for them to be added at runtime.");
            EditorGUILayout.PropertyField(messengerPlugins, true);

            generateTitle("Callbacks", "Implement these as functions in any script on this NetObject.\nIn example:\n\nvoid __uMMO_localPlayer_init() {\n    print(\"local player initialized\")\n}");
            strings2checkboxView(callbackOptions, "Callbacks");

            serializedObject.ApplyModifiedProperties();
        }