Пример #1
0
        private void Awake()
        {
#if UNITY_EDITOR
            HideStuff();
#endif
            if (DB == null)
            {
                DB = DatabasePhoton.Load();
            }

            character = gameObject.GetComponent <Character>();

            currentAngularSpeed = lastAngularSpeed = Locomotion.angularSpeed;
            currentJump         = lastJump = new Vector2(Locomotion.jumpForce, Locomotion.jumpTimes);
            currentGravity      = lastGravity = new Vector2(Locomotion.gravity, Locomotion.maxFallSpeed);
            currentControls     = lastControls = new Vector2(Locomotion.canRun ? 1 : 0, Locomotion.canJump ? 1 : 0);

            originalName = gameObject.name.Replace(CLONE, string.Empty);

#if PHOTON_RPG
            isNPC = character is NPCCharacter;
            npc   = character as NPCCharacter;
#endif

            if (character && PhotonNetwork.InRoom)
            {
                /*if (character is PlayerCharacter)
                 * {
                 *  if (!photonView.IsMine)
                 *  {
                 *      //locomotion.faceDirection = CharacterLocomotion.FACE_DIRECTION.None;
                 *      //locomotion.SetIsControllable(false);
                 *
                 *      HookPlayer hookPlayer = gameObject.GetComponent<HookPlayer>();
                 *      Destroy(hookPlayer);
                 *
                 *      /// Workaround to reset the HookPlayer reference to the local player.
                 *      if (Player)
                 *      {
                 *          hookPlayer = Player.GetComponent<HookPlayer>();
                 *          Destroy(hookPlayer);
                 *          Player.gameObject.AddComponent<HookPlayer>();
                 *      }
                 *  }
                 *  else
                 *  {
                 *      photonView.Owner.TagObject = gameObject;
                 *      Player = this;
                 *  }
                 * }*/
            }

#if PHOTON_RPG
            Actor.onActorReady  += (OnActorReady);
            Actor.onClassChange += (OnClassChange);
#endif
        }
Пример #2
0
        // INITIALIZERS: --------------------------------------------------------------------------

        private void Start()
        {
            if (Application.isPlaying)
            {
                if (PhotonNetwork.NetworkingClient != null)
                {
                    PhotonNetwork.AddCallbackTarget(this);
                }
                Application.logMessageReceived += LogReceived;

                DB = DatabasePhoton.Load();

                lastLagCheck = Time.time + DB.lagCheck * LAG_CHECK_DELAY;
            }
        }
Пример #3
0
        public NJGPhotonPool(DatabasePhoton db)
        {
            for (int i = 0; i < db.prefabs.Count; i++)
            {
                if (db.prefabs[i] == null)
                {
                    continue;
                }

                if (!ResourceCache.ContainsKey(db.prefabs[i].name))
                {
                    ResourceCache.Add(db.prefabs[i].name, db.prefabs[i]);
                }
            }
        }
Пример #4
0
        // PUBLIC METHODS: ---------------------------------------------------------------------------------------------

        public CachedPrefabPDWindow(Rect activatorRect, UnityAction <string> callback) //SkillHolderPD itemHolderPropertyDrawer
        {
            this.windowRect = new Rect(
                activatorRect.x,
                activatorRect.y + activatorRect.height,
                activatorRect.width,
                WIN_HEIGHT
                );

            this.inputfieldFocus = true;
            this.scroll          = Vector2.zero;
            this.callback        = callback;
            //this.itemHolderPropertyDrawer = itemHolderPropertyDrawer;

            if (DATABASE == null)
            {
                DATABASE = DatabasePhoton.LoadDatabase <DatabasePhoton>();
            }
        }
        // INITIALIZE: -------------------------------------------------------------------------------------------------

        private void OnEnable()
        {
            inst = target as DatabasePhoton;
            if (inst == null)
            {
                return;
            }

            prefabList = new ReorderableList(GetList(inst.prefabs), typeof(GameObject), true, true, false, true);
            prefabList.drawHeaderCallback += rect => GUI.Label(rect, new GUIContent("Photon Instantiate Prefabs"));
            prefabList.onAddCallback      += l =>
            {
                prefabList.list.Add(null);
            };
            prefabList.onSelectCallback += (ReorderableList list) =>
            {
                var prefab = list.list[list.index] as GameObject;
                if (prefab)
                {
                    EditorGUIUtility.PingObject(prefab.gameObject);
                }
            };
            prefabList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect.y += 2;

                if (index >= inst.prefabs.Count)
                {
                    return;
                }

                Rect nameRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
                var  prefab   = inst.prefabs[index];
                EditorGUI.LabelField(nameRect, prefab != null ? prefab.name : "(undefined)");
            };

            attachmentList = new ReorderableList(GetList(inst.attachments), typeof(GameObject), true, true, true, true);
            attachmentList.drawHeaderCallback += rect => GUI.Label(rect, new GUIContent("Attachments"));
            attachmentList.onSelectCallback   += (ReorderableList list) =>
            {
                var prefab = list.list[list.index] as GameObject;
                if (prefab)
                {
                    EditorGUIUtility.PingObject(prefab.gameObject);
                }
            };
            attachmentList.onAddCallback += l =>
            {
                attachmentList.list.Add(null);
            };
            attachmentList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) =>
            {
                rect.y += 2;

                if (index >= inst.attachments.Count)
                {
                    return;
                }

                Rect nameRect = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
                inst.attachments[index] = (GameObject)EditorGUI.ObjectField(nameRect, inst.attachments[index], typeof(GameObject), false);
            };

            this.tabIndex = EditorPrefs.GetInt(KEY_SIDEBAR_INDEX, 0);
            this.module   = ModuleManager.GetModuleManifest("com.ninjutsugames.modules.photon");

            //this.spMessageTarget = serializedObject.FindProperty("messageTarget");
            this.spMonoCache = serializedObject.FindProperty("monobehaviourCache");
        }
        // PRIVATE METHODS: --------------------------------------------------------------------------------------------

        private void DropAreaGUI(bool photonPrefab = true)
        {
            UnityEngine.Event evt = UnityEngine.Event.current;
            Rect drop_area        = GUILayoutUtility.GetRect(0.0f, 50.0f, GUILayout.ExpandWidth(true));
            Rect text_area        = drop_area;

            GUI.Box(drop_area, "", "ShurikenEffectBg");

            GUIStyle style = EditorStyles.centeredGreyMiniLabel;

            if (!InternalEditorUtility.HasPro())
            {
                style.normal.textColor = Color.white;
            }

            EditorGUI.LabelField(text_area, "To Add a new prefab just drag and drop it here.", style);
            switch (evt.type)
            {
            case EventType.DragUpdated:
            case EventType.DragPerform:
                if (!drop_area.Contains(evt.mousePosition))
                {
                    return;
                }

                DragAndDrop.visualMode = DragAndDropVisualMode.Copy;

                if (evt.type == EventType.DragPerform)
                {
                    DragAndDrop.AcceptDrag();

                    foreach (UnityEngine.Object draggedObject in DragAndDrop.objectReferences)
                    {
                        if (draggedObject is GameObject)
                        {
                            if (PrefabUtility.GetPrefabAssetType(draggedObject) == PrefabAssetType.Regular ||
                                PrefabUtility.GetPrefabAssetType(draggedObject) == PrefabAssetType.Variant)     //!photonPrefab || (photonPrefab
                            {
                                GameObject go = draggedObject as GameObject;
                                if (photonPrefab && DatabasePhoton.IsDefaultPrefab(go))
                                {
                                    bool result = EditorUtility.DisplayDialog("Error", "Cannot use default prefabs.\nDo you want to create a copy?", "Ok", "Cancel");
                                    if (result)
                                    {
                                        go = DatabasePhoton.CreatePrefabCopy(go);
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                                if (go == null)
                                {
                                    return;
                                }

                                if (photonPrefab && go.GetComponent <PhotonView>() == null)
                                {
                                    EditorUtility.DisplayDialog("Error", string.Format("This prefab needs to have a Photon View.", PrefabUtility.GetPrefabAssetType(draggedObject)), "Ok");
                                    return;
                                }

                                serializedObject.Update();

                                if (photonPrefab)
                                {
                                    if (!inst.prefabs.Contains(go))
                                    {
                                        serializedObject.FindProperty("prefabs").AddToObjectArray(go);
                                        //inst.prefabs.Add(go);
                                        AssetDatabase.SaveAssets();
                                    }
                                }
                                else
                                {
                                    if (!inst.attachments.Contains(go))
                                    {
                                        serializedObject.FindProperty("attachments").AddToObjectArray(go);
                                        //inst.attachments.Add(go);
                                        AssetDatabase.SaveAssets();
                                    }
                                }

                                serializedObject.ApplyModifiedProperties();
                            }
                            else
                            {
                                EditorUtility.DisplayDialog("Error", string.Format("Only Prefabs are allowed. Type: {0}", PrefabUtility.GetPrefabAssetType(draggedObject)), "Ok");
                            }
                        }
                        else
                        {
                            EditorUtility.DisplayDialog("Error", string.Format("Only GameObjects are allowed. Type: {0}", draggedObject), "Ok");
                        }
                    }

                    if (GUI.changed)
                    {
                        EditorUtility.SetDirty(inst);
                    }
                }
                break;
            }
        }
        // GUI METHODS: ------------------------------------------------------------------------------------------------

        public override void OnInspectorGUI()
        {
            inst = target as DatabasePhoton;
            this.OnPreferencesWindowGUI();
        }
Пример #8
0
        public static GameObject CreatePrefabCopy(GameObject prefab)
        {
            string lastPath = DatabasePhoton.Load().lastPath;

            //if (string.IsNullOrEmpty(lastPath))
            //{
            lastPath = GetPath(lastPath);
            //}
            if (string.IsNullOrEmpty(lastPath))
            {
                Debug.LogWarning("Nothing was created!");
                //EditorUtility.DisplayDialog("Could not create Prefab", "Prefab Path folder has not been defined", "Ok");
                return(null);
            }

            string prefabName = lastPath + "/" + prefab.name + ".prefab";

            DatabasePhoton.Load().lastPath = lastPath;

            //Object prefab2 = PrefabUtility.CreateEmptyPrefab(prefabName);
            //GameObject newPrefab = PrefabUtility.ReplacePrefab(prefab, prefab2, ReplacePrefabOptions.Default);
            //GameObject newPrefab = PrefabUtility.SaveAsPrefabAsset(new GameObject(prefab.name), lastPath);
            GameObject newPrefab = PrefabUtility.SaveAsPrefabAsset(prefab, lastPath);

            //DestroyImmediate(go);

            if (!DatabasePhoton.Load().prefabs.Contains(newPrefab))
            {
                DatabasePhoton.Load().prefabs.Add(newPrefab);

                /*SerializedObject so = new SerializedObject(Load());
                 * so.ApplyModifiedProperties();
                 * so.Update();*/
            }

            CharacterNetwork chnet     = newPrefab.GetComponent <CharacterNetwork>();
            Character        character = newPrefab.GetComponent <Character>();

#if PHOTON_UNITY_NETWORKING
            PhotonView pview = newPrefab.GetPhotonView();

            if (pview == null)
            {
                pview = newPrefab.AddComponent <PhotonView>();
            }

            if (chnet == null && character != null)
            {
                chnet = newPrefab.AddComponent <CharacterNetwork>();
            }

            if (pview.Synchronization == ViewSynchronization.Off)
            {
                pview.Synchronization = ViewSynchronization.UnreliableOnChange;
            }

            if (chnet != null && !pview.ObservedComponents.Contains(chnet))
            {
                pview.ObservedComponents.Add(chnet);
            }
#endif
            return(newPrefab);
        }