public override void HoldItem(SceneGameObject childOfElement, bool instancing = true) { MetallicBoxData metallicBoxData = (MetallicBoxData)data.data.GetDefaultValue(); childOfElement.gameObject.SetActive(true); var spawnPoint = CheckSpawnpointFit(childOfElement, true); if (spawnPoint != null) { if (instancing) { if (metallicBoxData.toolsList == null) { metallicBoxData.toolsList = new List <SceneGameObjectReference>(); } metallicBoxData.toolsList.Add(new SceneGameObjectReference(childOfElement)); data.data.SetDefaultValue(metallicBoxData); } childOfElement.transform.SetParent(spawnPoint); childOfElement.transform.localPosition = Vector3.zero; childOfElement.transform.localRotation = Quaternion.identity; // Evitar que los spawnpoint se muevan junto las herramientas childOfElement.transform.SetParent(this.gameObject.transform); } else { Debug.Log("Cannot place object with id " + childOfElement.data.id + " inside the container"); childOfElement.gameObject.SetActive(false); } }
// Start is called before the first frame update void Start() { var obj = SceneGameObject.InitOne(new Vector3(0, -3, 0), parent); MonsterManager.Singleton.Add(0, -3, obj); //obj.m_GameObject.transform.parent = parent; int n = 10; for (int i = -n; i < n; i += 1) { for (int j = -n; j < n; j += 1) { var tt = GameObject.Instantiate(p); tt.transform.position = new Vector3(i, j, 0.5f); if (i == n - 1 || j == n - 1 || i == -n || j == -n) { var tt1 = GameObject.Instantiate(p); tt1.transform.position = new Vector3(i, j, -0.5f); } } } //var obj2 = Resources.Load("Prefabs/Roles/Heros/aAirElement"); //Instantiate(obj2); }
public static bool CreatePrefab(string prefabID, SceneGameObject root, string name = "", int sprite = 0, ObjectCategory category = ObjectCategory.UserPrefabs) { if (string.IsNullOrEmpty(prefabID)) { return(false); } string prefabFolder = exportPath + "/"; if (!Directory.Exists(exportPath)) { Directory.CreateDirectory(prefabFolder); } SavedPrefab savedPrefab = new SavedPrefab { name = name, category = category, sprite = sprite, root = root.data.id, prefabObjects = new List <SceneGameObject>(root.GetComponentsInChildren <SceneGameObject>(true)) }; byte[] exportData = SerializationUtility.SerializeValue(savedPrefab, dataFormat); File.WriteAllBytes(exportPath + "/" + prefabID + ".nt", exportData); return(true); }
public void Use(SceneGameObject holder) { //叠加效果 if (holder.extList[guid] != null) { holder.extList[guid].OverLay(); return; } //启用拓展 else { this.holder = holder; ended = false; OnUse(); } //非持续类型直接结束 if (maxKeepTime == 0) { End(); } else { holder.extList[guid] = this; curKeepTime = 0; } }
public void ActiveObject(int objectIndex, int serverID) { bool isPreSet = objectIndex >= 0; int index = isPreSet ? objectIndex : -objectIndex; if (isPreSet) { if (index < preSetPrefabs.Length) { GameObject go = preSetPrefabs[index]; if (go == null) { return; } go.SetActive(true); SceneGameObject sgo = go.GetComponent <SceneGameObject>(); if (sgo != null) { ProtoPlayerInfo selfInfo = playerModel.GetPlayerInfo(); if (selfInfo != null) { sgo.SetSyncStatus(objectIndex, serverID, true, selfInfo.pos, sgo.GetStartPos(), sgo.GetStartRot()); sceneModel.AddSceneObject(sgo); } } } } }
private void InspectObject() { if (TryRaycastFromScreen(allLayersExceptFloor, out RaycastHit hit)) { SceneGameObject soc = hit.transform.GetComponent <SceneGameObject>(); if (soc != null) { if (currentSceneGameObject != null) { currentSceneGameObject.isMouseOver = false; } currentSceneGameObject = soc; currentSceneGameObject.isMouseOver = true; if (Input.GetMouseButtonDown(0)) { SessionManager.Instance.SetSelected(currentSceneGameObject.data.id); } } else if (currentSceneGameObject != null) { currentSceneGameObject.isMouseOver = false; } } else if (currentSceneGameObject != null) { currentSceneGameObject.isMouseOver = false; } }
public void RemoveSceneGameObject(string key) { if (sceneGameObjects.ContainsKey(key)) { SceneGameObject toRemove = sceneGameObjects[key]; sceneGameObjects.Remove(key); if (toRemove.data.graph != null) { showingGraph = sceneGraph; } if (!string.IsNullOrEmpty(toRemove.data.parent)) { SceneGameObject toRemoveParent = sceneGameObjects[toRemove.data.parent]; toRemoveParent.data.childs.Remove(key); Debug.Log("Removed from parent!"); } List <SceneGameObject> childsToRemove = new List <SceneGameObject>(toRemove.GetComponentsInChildren <SceneGameObject>()); foreach (SceneGameObject childToRemove in childsToRemove) { string childKey = childToRemove.data.id; sceneGameObjects.Remove(childKey); } Destroy(toRemove.gameObject); OnSceneGameObjectsChanged.Invoke(); OnGraphListChanged.Invoke(); } }
/// <summary> /// 移除场景物体 /// </summary> public void RemoveSceneObject(SceneGameObject sObject) { if (sceneObjs.ContainsKey(sObject.sync.serverID)) { sceneObjs.Remove(sObject.sync.serverID); } }
public void AddSceneObject(SceneGameObject sObject) { if (!sceneObjs.ContainsKey(sObject.sync.serverID)) { sceneObjs.Add(sObject.sync.serverID, sObject); } }
public SceneGameObject GetSceneObject(int serverID) { SceneGameObject result = null; sceneObjs.TryGetValue(serverID, out result); return(result); }
public void SetUpForExecution() { //Reset all variables to default values! foreach (var so in sceneGameObjects) { SceneGameObject scgo = so.Value; scgo.data.data.Reset(); if (scgo.data.graph != null && (scgo.data.graph.nodes.Count > 0 || scgo.data.graph.packedNodes.Count > 0)) { scgo.data.graph.StartExecution(); } } var userVars = userVariables.Keys.ToArray(); foreach (var uv in userVars) { var v = userVariables[uv]; v.Reset(); userVariables[uv] = v; } sceneGraph.StartExecution(); }
private Transform CheckSpawnpointFit(SceneGameObject previewSGO, bool isInstantiating = false) { BoxCollider bc = previewSGO.GetComponentInChildren <BoxCollider>(); if (bc != null) { List <int> numCollisions = new List <int>(); foreach (var sp in spawnPoints) { LayerMask allLayers = ~0; var hitCollider = Physics.OverlapBox(sp.position, bc.size / 2, bc.transform.rotation, allLayers, QueryTriggerInteraction.Ignore); if (hitCollider.Length == 0) { return(sp); } numCollisions.Add(hitCollider.Length); // Rotate 90º? Rotate the same angle as the box? // var hitColliderRotated = Physics.OverlapBox(sp.position, bc.size / 2, bc.transform.rotation * Quaternion.Euler(0, 90, 0), allLayers, QueryTriggerInteraction.Ignore); // || hitColliderRotated.Length == 0 } if (isInstantiating) { int minValuePosition = numCollisions.IndexOf(numCollisions.Min()); return(spawnPoints[minValuePosition]); } } return(null); }
public override SceneGameObject Instantiate(string key, Transform parent, Vector3 localPosition, Quaternion localRotation ) { GameObject instancedGo = CraftPrefab(parent); instancedGo.SetActive(true); instancedGo.transform.localPosition = localPosition; instancedGo.transform.localRotation = localRotation; SceneGameObject scgo = instancedGo.GetComponent <SceneGameObject>(); if (scgo == null) { Debug.LogError("Fatal error on prefab!"); } SceneGameObject[] prefabSCGOs = instancedGo.GetComponentsInChildren <SceneGameObject>(true); foreach (SceneGameObject prefabSCGO in prefabSCGOs) { if (prefabSCGO == scgo) { continue; } SessionManager.Instance.AddSceneGameObject(prefabSCGO); } return(scgo); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag(TagCfg.SHIP)) { SceneGameObject sgo = other.gameObject.GetComponent <SceneGameObject>(); ReqGetProp(null); } }
public override bool CanHoldItem(SceneGameObject previewSGO) { MetallicBoxData metallicBoxData = (MetallicBoxData)data.data.GetValue(); Transform spawnPoint = CheckSpawnpointFit(previewSGO); bool freeSpace = spawnPoint != null; return(freeSpace && previewSGO is ITool); }
public void SetValue(string key, object value) { SceneGameObject scgo = GetSceneGameObject(key); if (scgo != null) { scgo.data.data.SetValue(value); } }
public void Add(PosVector index, SceneGameObject obj) { if (monsterMap.ContainsKey(index)) { Debug.LogError("duplicat index:x=" + index.x + ",y=" + index.y); return; } monsterMap.Add(index, obj); }
public void SetSceneObjectAciton(int serverID, int[] data) { SceneGameObject obj = GetSceneObject(serverID); if (obj != null) { obj.OnGetAction(data); } }
public override void SetDamage(int atk, Vector3 point, SceneGameObject sgo) { hp = hp - atk; OnGetDamage(atk, point); if (hp < 0) { ReqGetProp(sgo); } }
public object GetValue(string key) { SceneGameObject scgo = GetSceneGameObject(key); if (scgo != null) { return(scgo.data.data.GetValue()); } return(null); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag(TagCfg.SHIP)) { SceneGameObject sgo = other.gameObject.GetComponent <SceneGameObject>(); if (sgo != null) { sgo.SetDamage(rushPower, transform.position, this); OnRush(); } } }
public void AddSceneGameObject(SceneGameObject so) { sceneGameObjects.Add(so.data.id, so); if (so.data.graph != null) { so.data.graph.variableDelegate = this; } OnSceneGameObjectsChanged.Invoke(); OnGraphListChanged.Invoke(); }
private void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag(tagetTag)) { SceneGameObject sgo = other.gameObject.GetComponent <SceneGameObject>(); if (sgo != null) { sgo.SetDamage(power, transform.position, master); } Recycle(); } }
/// <summary> /// 触发伤害者调用 /// </summary> /// <param name="atk"></param> /// <param name="point"></param> public virtual void SetDamage(int atk, Vector3 point, SceneGameObject from) { hp = hp - atk; OnGetDamage(atk, point); if (Connection.GetInstance().isHost) { if (hp < 0) { ReqDestroy(); } } }
/// <summary> /// 创建场景对象 /// </summary> /// <param name="objInfo"></param> public void CreateObject(int objectIndex, int serverID, ProtoCreateObject sync) { bool isPreSet = objectIndex >= 0; int index = isPreSet ? objectIndex : -objectIndex; if (index < cratePrefabs.Length) { GameObject prefab = cratePrefabs[index]; if (prefab == null) { Debug.LogError("生成AI:无效对象索引" + objectIndex); return; } GameObject go = GameObject.Instantiate(prefab); #if UNITY_EDITOR go.name = "" + serverID; #endif if (!go.activeSelf) { go.SetActive(true); } //获取/初始化配置数据 BaseAI ai = go.GetComponent <BaseAI>(); if (ai != null) { if (Connection.GetInstance().isHost == true) { AppearObjectData objCfg = AICreater.GetObjectCfg(sync.hashCode); if (objCfg != null) { ai.InitAIData(objCfg); } } sceneModel.RegisterAI(ai); } //设置同步组件 SceneGameObject sgo = go.GetComponent <SceneGameObject>(); if (sgo != null) { ProtoPlayerInfo selfInfo = playerModel.GetPlayerInfo(); if (selfInfo != null) { sgo.SetSyncStatus(objectIndex, serverID, true, selfInfo.pos, sync.GetPos(), sync.GetRot()); sceneModel.AddSceneObject(sgo); } } } else { Debug.LogError("生成AI:无效对象索引" + objectIndex); } }
public override List <string> GetCallbacks() { assignedSCGO = SessionManager.Instance.GetSceneGameObject(linkedNTVariable); if (assignedSCGO != null) { return(assignedSCGO.sceneObject.GetCallbacks()); } else { return(new List <string>()); } }
private void OnCurrentChanged() { current = SessionManager.Instance.selectedSceneObject; object value = null; if (current != null) { value = current.data.data.GetDefaultValue(); SetCurrent(current.sceneObject.GetDisplayName(), value); } else { Inspect(null, null); } }
public override bool CanHoldItem(SceneGameObject previewSceneGameObject) { ClosetData closetData = (ClosetData)data.data.GetValue(); List <SceneGameObjectReference> slots = SlotsList(closetData); bool freeSpace = false; foreach (var s in slots) { freeSpace = freeSpace || s == null; } return(freeSpace && previewSceneGameObject is ITool); }
public override void OnDataSetted() { SceneGameObject sceneGameObject = SessionManager.Instance.GetSceneGameObject(data.key); if (sceneGameObject != null) { if (sceneGameObject.sceneObject.GetCallbacks().Count > 0) { graphButton.gameObject.SetActive(true); } else { graphButton.gameObject.SetActive(false); } } }
public override void HoldItem(SceneGameObject childOfElement, bool instancing = true) { ClosetData closetData = (ClosetData)data.data.GetDefaultValue(); List <SceneGameObjectReference> slots = SlotsList(closetData); //Destroy(childOfElement.GetComponent<Rigidbody>()); childOfElement.gameObject.SetActive(true); if (instancing) { bool stored = false; for (int i = 0; i < slots.Count && !stored; i++) { if (slots[i] == null) { stored = true; slots[i] = new SceneGameObjectReference(childOfElement); } } ListToSlots(ref closetData, slots); data.data.SetDefaultValue(closetData); } else { for (int i = 0; i < slots.Count; i++) { if (slots[i].linkedSGO == childOfElement.data.id) { childOfElement.transform.SetParent(slotPivot[i]); childOfElement.transform.localPosition = Vector3.zero; childOfElement.transform.localRotation = Quaternion.identity; slotPivot[i].gameObject.SetActive(true); return; } } Debug.Log("There is no slot for ?¿" + childOfElement.data.id); childOfElement.gameObject.SetActive(false); } }