/// <summary> /// 加载 /// </summary> /// <param name="isEditor">是否是编辑器</param> public void Load(bool isEditor = false) { if (string.IsNullOrEmpty(actionInteractivePrefabName)) { ActionInteractiveObjPrefab = null; } if (ActionInteractiveObjPrefab == null) { if (!string.IsNullOrEmpty(actionInteractivePrefabName)) { ActionInteractiveObjPrefab = Resources.Load <GameObject>(prefabDirectoryPath + "/" + actionInteractivePrefabName); } } if (ActionInteractiveObj == null && ActionInteractiveObjPrefab != null) { ActionInteractiveObj = GameObject.Instantiate <GameObject>(ActionInteractiveObjPrefab, ActionInteractiveLocation, Quaternion.identity); ActionInteractiveObj.transform.eulerAngles = ActionInteractiveAngle; ActionInteractiveObj.name = ActionInteractiveName; if (isEditor)//如果是编辑器直接返回 { return; } ActionInteractiveDataInfoMono addScript = null; switch (ActionInteractiveType) { case EnumActionInteractiveType.None: //此时的otherValue为null addScript = ActionInteractiveObj.AddComponent <ActionInteractiveDataInfoMono>(); break; case EnumActionInteractiveType.TreasureBox: //此时的otherValue为物品与数量之间的字典 addScript = ActionInteractiveObj.AddComponent <ActionInteractiveDataInfoMono_TreasureBox>(); break; case EnumActionInteractiveType.Other: //此时的otherValue为OtherDataStruct数据 if (OtherValue != null) { OtherDataStruct otherDataStruct = OtherValue as OtherDataStruct; if (otherDataStruct != null && otherDataStruct.ActionInterativeClass != null) { Component component = ActionInteractiveObj.AddComponent(otherDataStruct.ActionInterativeClass); addScript = component as ActionInteractiveDataInfoMono; } } break; default: break; } if (addScript == null) { return; } addScript.ActionInteractiveDataInfo = this; ActionInteractiveStateData actionInteractiveStateData = DataCenter.Instance.GetEntity <ActionInteractiveStateData>(); if (actionInteractiveStateData != null) { if (!actionInteractiveStateData.SceneDic.ContainsKey(SceneName)) { actionInteractiveStateData.SceneDic.Add(SceneName, new ActionInteractiveStateData.SceneData()); } ActionInteractiveStateData.SceneData sceneData = actionInteractiveStateData.SceneDic[SceneName]; if (!sceneData.IDDic.ContainsKey(ActionInteractiveID)) { sceneData.IDDic.Add(ActionInteractiveID, null); } addScript.LoadData(sceneData.IDDic[ActionInteractiveID], temp => sceneData.IDDic[ActionInteractiveID] = temp); } } }
private void OnTriggerEnter(Collider other) { int layer = (int)Mathf.Pow(2, other.gameObject.layer); if (layerMaks.value == (layerMaks.value | layer)) { IDataInfoType iDataInfoType = other.gameObject.GetComponent <IDataInfoType>(); if (iDataInfoType != null) { if (!GameObject.Equals(nowObj, other.gameObject)) { GameObject lastObj = nowObj; nowObj = other.gameObject; IPlayerState iPlayerState = GameState.Instance.GetEntity <IPlayerState>(); if (Type.Equals(iDataInfoType.T, typeof(StuffDataInfoMono))) { StuffDataInfoMono stuffDataInfoMono = iDataInfoType as StuffDataInfoMono; if (stuffDataInfoMono.StuffDataInfo.ResidualCount() <= 0) { //尝试刷新 stuffDataInfoMono.StuffDataInfo.Update(); } //如果大于零则表示可以 if (stuffDataInfoMono.StuffDataInfo.ResidualCount() > 0) { iPlayerState.TouchTargetStruct = new TouchTargetStruct() { ID = stuffDataInfoMono.StuffDataInfo.StuffID, TerrainName = stuffDataInfoMono.StuffDataInfo.SceneName, TouchTargetType = TouchTargetStruct.EnumTouchTargetType.Stuff }; } else { nowObj = lastObj; } } else if (Type.Equals(iDataInfoType.T, typeof(NPCDataInfoMono))) { NPCDataInfoMono npcDataInfoMono = iDataInfoType as NPCDataInfoMono; iPlayerState.TouchTargetStruct = new TouchTargetStruct() { ID = npcDataInfoMono.NPCDataInfo.NPCID, TerrainName = npcDataInfoMono.NPCDataInfo.SceneName, TouchTargetType = TouchTargetStruct.EnumTouchTargetType.NPC }; } else if (Type.Equals(iDataInfoType.T, typeof(ActionInteractiveDataInfoMono))) { ActionInteractiveDataInfoMono actionInteractiveDataInfoMono = iDataInfoType as ActionInteractiveDataInfoMono; iPlayerState.TouchTargetStruct = new TouchTargetStruct() { ID = actionInteractiveDataInfoMono.ActionInteractiveDataInfo.ActionInteractiveID, TerrainName = actionInteractiveDataInfoMono.ActionInteractiveDataInfo.SceneName, TouchTargetType = TouchTargetStruct.EnumTouchTargetType.Action }; } } } } }