private void Start() { if (_view == null) { _view = this.gameObject.AddComponent <MonobitView>(); } }
/** * */ void AddMonobitObserverdComponent() { if (view == null) { view = obj.gameObject.GetComponent <MonobitView>(); } if (view != null) { if (view.InternalObservedComponents == null) { view.InternalObservedComponents = new List <Component>(); } else { if (view.InternalObservedComponents.FindAll(item => item != null && item.GetType() == typeof(MonobitTransformView)).Count == 0) { view.InternalObservedComponents.Add(obj.gameObject.GetComponent <MonobitTransformView>()); } if (view.InternalObservedComponents.FindAll(item => item != null && item.GetType() == typeof(MonobitAnimatorView)).Count == 0) { view.InternalObservedComponents.Add(obj.gameObject.GetComponent <MonobitAnimatorView>()); } } } }
/** * @brief Inspector上のGUI表示. */ public override void OnInspectorGUI() { // 変数取得 m_View = target as MonobitView; if (m_View == null) { return; } bool bPrefab = EditorUtility.IsPersistent(m_View.gameObject); // 監視コンポーネントリストの初期化 InitializeObservedComponentList(); // 統括設定 GeneralSettings(bPrefab); // 監視コンポーネントリストの設定 try { ObservedComponentListSettings(); } catch (Exception) { } // セーブ if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(m_View); } }
/** * @brief Inspector に追加されたときの処理. */ public void Awake() { // 変数取得 m_View = target as MonobitView; if (m_View == null) { return; } m_GameObject = m_View.gameObject; // シーン内のオブジェクトでIDが重複している場合、警告を促す m_ViewIdOverlapped = MonobitView.OverlappedSceneViewID(m_View.viewID); }
private void Awake() { // すべての親オブジェクトに対して MonobitView コンポーネントを検索する if (this.GetComponentInParent <MonobitView>() != null) { this.enemyMonobitView = this.GetComponentInParent <MonobitView>(); } // 親オブジェクトに存在しない場合、すべての子オブジェクトに対して MonobitView コンポーネントを検索する else if (this.GetComponentInChildren <MonobitView>() != null) { this.enemyMonobitView = this.GetComponentInChildren <MonobitView>(); } // 親子オブジェクトに存在しない場合、自身のオブジェクトに対して MonobitView コンポーネントを検索して設定する else { this.enemyMonobitView = this.GetComponent <MonobitView>(); } }
/// <summary> /// 親階層子階層のすべてから MonobitViewを探し出す /// </summary> void Awake() { // すべての親オブジェクトに対して MonobitView コンポーネントを検索する if (GetComponentInParent <MonobitView>() != null) { _monobitView = GetComponentInParent <MonobitView>(); } // 親オブジェクトに存在しない場合、すべての子オブジェクトに対して MonobitView コンポーネントを検索する else if (GetComponentInChildren <MonobitView>() != null) { _monobitView = GetComponentInChildren <MonobitView>(); } // 親子オブジェクトに存在しない場合、自身のオブジェクトに対して MonobitView コンポーネントを検索して設定する else { _monobitView = GetComponent <MonobitView>(); } }
// Start is called before the first frame update void Start() { //起動時のウィンドウサイズを(500,500)に設定 >>正直このスクリプトでやる意味ない /*Screen.SetResolution(500, 500, false); * * //入室関係------------------------------------------------------- * //InputField取得 * _nameObject = GameObject.Find("NameField"); * _nameField = _nameObject.GetComponent<InputField>(); * _nameField.ActivateInputField(); * _nameField.onEndEdit.AddListener(EnterRoom); * * //ボタン取得 * _enterObject = GameObject.Find("EnterButton"); * _leaveObject = GameObject.Find("LeaveButton"); * _enterBtn = _enterObject.GetComponent<Button>(); * _leaveBtn = _leaveObject.GetComponent<Button>(); * * _leaveObject.SetActive(false); * * //イベント設定 * _enterBtn.onClick.AddListener(EnterRoom); * _leaveBtn.onClick.AddListener(LeaveRoom); * * * //--------------------------------------------------------------- * * //カメラ関係---------------------------------------------- * _defaultTarget = GameObject.Find("front").transform; //カメラ注視オブジェクト * _cameraCtrl = Camera.main.gameObject.GetComponent<CameraCtrl>();//コンポーネント * _cameraCtrl.target = _defaultTarget; //注視点セット */ //monobitview 取得 _monobitView = this.gameObject.GetComponent <MonobitView>(); //ギミック取得 //_gimmick = GameObject.Find("Gimmick"); _view = _monobitView; }
/** * @brief Inspector から削除されたときの処理. */ public void OnDestroy() { // 変数取得 m_View = target as MonobitView; if (m_View != null) { return; } if (m_GameObject != null) { bool bPrefab = EditorUtility.IsPersistent(m_GameObject); if (!bPrefab && m_ViewID != 0) { // 0 以外が入っていた場合には MonobitView.RemoveSceneViewID() で自動削除 MonobitView.RemoveSceneViewID(m_ViewID); } } }
/** * @brief Inspector に追加されたときの処理. */ public void Awake() { // 変数取得 m_View = target as MonobitView; if (m_View == null) { return; } m_GameObject = m_View.gameObject; // 0 が入っていた場合には MonobitView.AllocateSceneViewID() で自動割り当て bool bPrefab = EditorUtility.IsPersistent(m_View.gameObject); if (!bPrefab && m_View.viewID == 0) { Int32 tmp = MonobitView.AllocateSceneViewID(); m_View.viewID = (tmp >= MonobitNetwork.PERSONAL_VIEW_ID_MAX) ? 0 : tmp; } // シーン内のオブジェクトでIDが重複している場合、警告を促す m_ViewIdOverlapped = MonobitView.OverlappedSceneViewID(m_View.viewID); }
// Update is called once per frame public void Update() { if (monobitView.isOwner) { // キャラクタの移動&アニメーション切り替え if (Input.GetKey("up")) { gameObject.transform.position += gameObject.transform.forward * 0.1f; animator.SetInteger(animId, 1); } else { animator.SetInteger(animId, 0); } if (Input.GetKey("right")) { gameObject.transform.Rotate(0, 2.0f, 0); } if (Input.GetKey("left")) { gameObject.transform.Rotate(0, -2.0f, 0); } if (Input.GetKeyDown("z")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0); } if (Input.GetKeyDown("s")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0, null, true, false, true); } if (Input.GetKeyDown("e")) { MonobitNetwork.Instantiate("Cube", transform.position, transform.rotation, 0, null, true, false, false); } if (Input.GetKeyDown("d")) { UnityEngine.Debug.Log("Destroy Cube Start"); foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } MonobitNetwork.Destroy(go); if (!view.enabled) { UnityEngine.Debug.Log("Destroy Cube: " + view); } } UnityEngine.Debug.Log("Destroy Cube End"); } if (Input.GetKeyDown("r")) { UnityEngine.Debug.Log("RequestOwnership Cube Start"); foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } view.RequestOwnership(); UnityEngine.Debug.Log("RequestOwnership Cube: " + view); } UnityEngine.Debug.Log("RequestOwnership Cube End"); } if (Input.GetKeyDown("t")) { UnityEngine.Debug.Log("TransferOwnership Cube Start"); int playerId = MonobitNetwork.player.ID; foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } view.TransferOwnership(playerId); UnityEngine.Debug.Log("TransferOwnership Cube: " + view); } UnityEngine.Debug.Log("TransferOwnership Cube End"); } if (Input.GetKeyDown("i")) { UnityEngine.Debug.Log("Change IsDontDestroyOnRoom Cube Start"); foreach (GameObject go in FindObjectsOfType(typeof(GameObject))) { MonobitView view = go.GetComponent <MonobitView>(); if (null == view) { continue; } if ("Cube(Clone)" != go.name) { continue; } bool isDontDestroyOnRoom = view.isDontDestroyOnRoom; view.isDontDestroyOnRoom = !isDontDestroyOnRoom; if (isDontDestroyOnRoom != view.isDontDestroyOnRoom) { UnityEngine.Debug.Log("Change IsDontDestroyOnRoom Cube: " + view + " " + isDontDestroyOnRoom + " -> " + view.isDontDestroyOnRoom); } } UnityEngine.Debug.Log("Change IsDontDestroyOnRoom Cube End"); } if (Input.GetKeyDown("0")) { serializeBytes[0] = 0; } if (Input.GetKeyDown("1")) { serializeBytes[0] = 1; } } }
/** * 統括設定. * * @param bPrefab プレハブかどうかのフラグ */ private void GeneralSettings(bool bPrefab) { GUILayout.Space(5); // 標題の表示 EditorGUILayout.LabelField("General Settings", EditorStyles.boldLabel); EditorGUI.indentLevel = 2; // MonobitView ID の表示 if (bPrefab) { EditorGUILayout.LabelField("MonobitView ID", "Decide at runtime"); if (0 != m_View.viewID) { m_View.viewID = 0; } } else if (EditorApplication.isPlaying) { EditorGUILayout.LabelField("MonobitView ID", m_View.viewID.ToString()); } else { // MonobitView ID の手動登録 int viewID = (int)EditorGUILayout.IntField("MonobitView ID", m_View.viewID); if (viewID != m_View.viewID) { MonobitView.RemoveSceneViewID(m_View.viewID); m_View.viewID = MonobitView.AssignedSceneViewID(viewID); m_ViewIdOverlapped = MonobitView.OverlappedSceneViewID(viewID); } // MonobitView ID の退避 m_ViewID = m_View.viewID; // シーン内のオブジェクトでIDが重複している場合、警告を促す if (m_ViewIdOverlapped) { EditorGUILayout.HelpBox("This \"MonobitView ID\" is stored in another object.", MessageType.Warning, true); } // 登録されたIDが不正である場合、エラーを出力する if (m_View.viewID < 0 || m_View.viewID >= MonobitNetwork.PERSONAL_VIEW_ID_MAX) { EditorGUILayout.HelpBox("This \"MonobitView ID\" doesn't allowed as this value (must between 0 to 999).", MessageType.Error, true); } } // Owner の表示 if (bPrefab) { EditorGUILayout.LabelField("Owner", "Decide at runtime"); } else if (m_View.isSceneView) { EditorGUILayout.LabelField("Owner", "Scene(HostClient)"); } else { MonobitPlayer player = MonobitPlayer.Find(m_View.ownerId); string playerInfo = (player != null) ? player.name : "<MonobitPlayer is not found>"; if (string.IsNullOrEmpty(playerInfo)) { playerInfo = "<playername is not set>"; } EditorGUILayout.LabelField("Owner", "[" + m_View.ownerId + "]" + playerInfo); } // Ownerの所有権委譲の設定 GUI.enabled = !EditorApplication.isPlaying; m_View.ownershipTransfer = (MonobitEngineBase.OwnershipOption)EditorGUILayout.EnumPopup("Ownership Transfer", m_View.ownershipTransfer); GUI.enabled = true; // 制御権の表示 if (EditorApplication.isPlaying && MonobitNetwork.player != null) { EditorGUILayout.Toggle("Enable Control" + (MonobitNetwork.isHost ? " <master>" : ""), m_View.isMine); } else { GUI.enabled = false; EditorGUILayout.Toggle("Enable Control", true); GUI.enabled = true; } // 暗号化の有効/無効フラグ m_View.Encrypt = EditorGUILayout.Toggle("Enable Sync Encrypt Network", m_View.Encrypt); // 所有者がルーム退室時にオブジェクトを削除するかどうか if (m_View.isInstantiated) { GUI.enabled = false; EditorGUILayout.Toggle("Is Dont Destroy On Room", m_View.isDontDestroyOnRoom); GUI.enabled = true; } EditorGUI.indentLevel = 0; GUILayout.Space(5); }