Example #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
        }
Example #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;
            }
        }
        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);
        }