public static void FixPrefab(GameObject sourcePrefab, out GameObject newPrefab) { GameObject np = null; if (IsDefaultPrefab(sourcePrefab)) { np = CreatePrefabCopy(sourcePrefab); //if (newPrefab != null) prefab = newPrefab.name; } else { CharacterNetwork chnet = sourcePrefab.GetComponent <CharacterNetwork>(); Character character = sourcePrefab.GetComponent <Character>(); #if PHOTON_UNITY_NETWORKING PhotonView pview = sourcePrefab.GetPhotonView(); if (!Load().prefabs.Contains(sourcePrefab)) { Load().prefabs.Add(sourcePrefab); /*SerializedObject so = new SerializedObject(Load()); * so.ApplyModifiedProperties(); * so.Update();*/ } if (chnet == null && character != null) { chnet = sourcePrefab.AddComponent <CharacterNetwork>(); } if (pview == null) { pview = sourcePrefab.AddComponent <PhotonView>(); } if (pview.Synchronization == ViewSynchronization.Off) { pview.Synchronization = ViewSynchronization.UnreliableOnChange; } if (!pview.ObservedComponents.Contains(chnet)) { pview.ObservedComponents.Add(chnet); } #endif np = sourcePrefab; } newPrefab = np; }
// INITIALIZERS: ----------------------------------------------------------------------------------------------- protected void OnEnable() { if (target == null) { return; } this.character = (CharacterNetwork)target; this.spTeleportDistance = serializedObject.FindProperty(PROP_TELEPORT); //this.spRotationDamp = serializedObject.FindProperty(PROP_ROTATION); this.spSyncAttachments = serializedObject.FindProperty(PROP_ATTACHMENTS); this.spCulling = serializedObject.FindProperty(PROP_CULLING); this.spLocomotion = serializedObject.FindProperty(PROP_LOCOMOTION); if (this.target != null) { this.target.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy; } }
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); }
protected void OnDisable() { this.character = null; }
public override void OnInspectorGUI() { if (serializedObject == null) { return; } base.OnInspectorGUI(); EditorGUILayout.BeginVertical(); GUILayout.Space(-3); if (this.section == null) { this.section = new Section("Network Settings", GetTexture("ActionNetwork.png"), this.Repaint); } if (!initialized) { characterNetwork = character.GetComponent <CharacterNetwork>(); if (characterNetwork != null && characterNetworkEditor == null) { characterNetworkEditor = (CharacterNetworkEditor)Editor.CreateEditor(characterNetwork, typeof(CharacterNetworkEditor)); } hasComponent = characterNetwork != null; initialized = true; } bool hasChanged = false; this.section.PaintSection(); using (var group = new EditorGUILayout.FadeGroupScope(this.section.state.faded)) { if (group.visible) { EditorGUILayout.BeginVertical(CoreGUIStyles.GetBoxExpanded()); EditorGUI.BeginChangeCheck(); hasComponent = EditorGUILayout.Toggle(GUI_SYNC, hasComponent); hasChanged = EditorGUI.EndChangeCheck(); if (characterNetworkEditor != null) { characterNetworkEditor.serializedObject.Update(); characterNetworkEditor.PaintInspector(); characterNetworkEditor.serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndVertical(); } } if (hasChanged) { if (characterNetwork != null) { DestroyImmediate(characterNetworkEditor); DestroyImmediate(characterNetwork, true); EditorGUIUtility.ExitGUI(); characterNetwork = null; characterNetworkEditor = null; initialized = false; } else { characterNetwork = character.GetComponent <CharacterNetwork>() ?? character.gameObject.AddComponent <CharacterNetwork>(); characterNetwork.SetupPhotonView(); characterNetworkEditor = (CharacterNetworkEditor)Editor.CreateEditor(characterNetwork, typeof(CharacterNetworkEditor)); characterNetwork.hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy; hasComponent = true; } hasChanged = false; } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); }