public void initializeMap() { points = GameObject.FindGameObjectsWithTag("Point"); matrix = new Vertex[points.Length + 1, points.Length + 1]; objs = gameObject.GetComponent <GameObjectHolder>(); matrix[0, 0] = new Vertex(); for (int i = 1; i < points.Length + 1; i++) { matrix[0, i] = new Vertex(); matrix[0, i].setVertex(points[i - 1].name); matrix[i, 0] = new Vertex(); matrix[i, 0].setVertex(points[i - 1].name); } for (int i = 1; i < points.Length + 1; i++) { for (int k = 1; k < points.Length + 1; k++) { matrix[i, k] = new Vertex(); matrix[i, k].setVertex(points[k - 1].name); //Debug.Log("[" + i + ", " + k + "]" + " = " + matrix[i, k].getName()); } } }
// Use this for initialization public void Init() { m_gProgress = Instantiate(Resources.Load(PROGRESS_BAR_PREFAB)) as GameObject; m_gProgressBar = m_gProgress.GetComponent <GameObjectHolder>().FocusItem0; //Set up Bar GameObjectHolder component = m_gProgress.GetComponent <GameObjectHolder>(); if (component) { Debug.Log("ProgressBar: Init: Component: Found It"); m_gProgressBar = component.FocusItem0; m_gLeft = component.FocusItem1; m_gRight = component.Background; } else { Debug.Log("ProgressBar: Init: Component: Can't Find It"); } //Get your data m_iTotalRails = Game.game.Rails; m_vDivision = (m_gRight.transform.position - m_gLeft.transform.position) / (m_iTotalRails - 1); Reset(); }
private static void DontDestroyOnLoadInner(this GameObject go, int priority = 0, Action on_destory = null) //on_destory主要用来定制处理静态变量的状态 { UnityEngine.Object.DontDestroyOnLoad(go); GameObjectHolder holder = new GameObjectHolder(); holder.go = go; holder.priority = priority; holder.name = go.name; _ddolObjects.Add(holder); _ddolObjects.Sort((a, b) => { if (a.priority < b.priority) { return(-1); } else if (a.priority > b.priority) { return(1); } else { return(0); } }); if (on_destory != null) { _map[go] = on_destory; } }
// Use this for initialization public void Init() { m_dInputToPosition = new Dictionary <KeyCode, int>(); m_dInputToPosition[m_kLeftKey] = STAKE_LEFT; m_dInputToPosition[m_kCenterKey] = STAKE_NORMAL; m_dInputToPosition[m_kRightKey] = STAKE_RIGHT; m_dPositionToRotation = new Dictionary <int, float>(); m_dPositionToRotation[STAKE_LEFT] = 20f; m_dPositionToRotation[STAKE_NORMAL] = 0f; m_dPositionToRotation[STAKE_RIGHT] = -20f; //Set up Bar GameObjectHolder component = gameObject.GetComponent <GameObjectHolder>(); if (component) { Debug.Log("StakeGame: Init: Component: Found It"); m_gPlayerStake = component.FocusItem0; m_gAIStake = component.FocusItem1; m_gHammer = component.AnimatedObj; m_gAudio = component.AudioObj; m_animHammerAnim = m_gHammer.GetComponent <Animator>(); m_audAudioSource = m_gAudio.GetComponent <AudioSource>(); m_cAudioHolder = m_gAudio.GetComponent <AudioHolder>(); } else { Debug.Log("StakeGame: Init: Failed"); } Reset(); }
public void Init() { m_gBeatBar = Instantiate(Resources.Load(STAGE_BEAT_BAR)) as GameObject; m_gBeatBar.transform.SetParent(gameObject.transform, false); m_cBeatBarItems = m_gBeatBar.GetComponent <GameObjectHolder>(); m_cSpriteHolder = m_gBeatBar.GetComponent <SpriteHolder>(); m_gIconStart = m_cBeatBarItems.gObjects[0]; m_gIconEnd = m_cBeatBarItems.gObjects[1]; m_gBossIcon = Instantiate(Resources.Load(STAGE_BOSS_ICON)) as GameObject; m_gBossIcon.transform.SetParent(m_gBeatBar.transform, false); m_gBossIcon.transform.localPosition = m_gIconStart.transform.localPosition; m_gPlayerIcon = Instantiate(Resources.Load(STAGE_PLAYER_ICON)) as GameObject; m_gPlayerIcon.transform.SetParent(m_gBeatBar.transform, false); m_gPlayerIcon.transform.localPosition = m_gIconStart.transform.localPosition; colScript = m_gPlayerIcon.GetComponent <ColliderScript>(); m_arrStrings = new string[] { BUTTON_A, BUTTON_S, BUTTON_D }; m_dStringToKey = new Dictionary <string, KeyCode>(); m_dStringToKey[BUTTON_A] = KeyCode.A; m_dStringToKey[BUTTON_S] = KeyCode.S; m_dStringToKey[BUTTON_D] = KeyCode.D; m_dStringToKey[BUTTON_NONE] = KeyCode.At; m_dStringKeyToSprite = new Dictionary <string, Sprite>(); m_dStringKeyToSprite[BUTTON_A] = m_cSpriteHolder.m_sprSpriteObj[0]; m_dStringKeyToSprite[BUTTON_S] = m_cSpriteHolder.m_sprSpriteObj[1]; m_dStringKeyToSprite[BUTTON_D] = m_cSpriteHolder.m_sprSpriteObj[2]; m_iDotArrStart = 3; m_iDotArrEnd = 19; int totalDots = m_iDotArrEnd - m_iDotArrStart; m_arrDots = new GameObject[totalDots]; m_dGameObjToArr = new Dictionary <GameObject, int>(); m_dPlayerDotData = new Dictionary <int, bool>(); m_dArrToStringKey = new Dictionary <int, string>(); m_dArrToDefaultSprite = new Dictionary <int, Sprite>(); for (int i = 0; i < DOTS_TOTAL; ++i) { m_arrDots[i] = m_cBeatBarItems.gObjects[i + m_iDotArrStart]; m_dGameObjToArr[m_arrDots[i]] = i; m_dPlayerDotData[i] = false; m_dArrToStringKey[i] = BUTTON_NONE; if (i != 0 && (i + 1) % 4 == 0) { m_dArrToDefaultSprite[i] = m_cSpriteHolder.m_sprSpriteObj[4]; } else { m_dArrToDefaultSprite[i] = m_cSpriteHolder.m_sprSpriteObj[3]; } } BossTurn(); }
// Use this for initialization public void Init() { m_gComboObject = Instantiate(Resources.Load(CANVAS_COMBO)) as GameObject; m_gComboObject.transform.SetParent(Game.game.canvas.gameObject.transform, false); GameObjectHolder holder = m_gComboObject.GetComponent <GameObjectHolder>(); ComboTitleText = holder.gObjects[0].GetComponent <Text>(); ComboTitleText.text = TEXT_COMBO_STRING; //ComboText = holder.gObjects[1].GetComponent<Text>(); //ComboText.text = ""; m_gComboObject.SetActive(false); }
// Use this for initialization public void Init() { m_gComboObject = Instantiate(Resources.Load(CANVAS_COMBO)) as GameObject; m_gComboObject.transform.SetParent(Game.game.canvas.gameObject.transform, false); GameObjectHolder holder = m_gComboObject.GetComponent <GameObjectHolder>(); ComboTitleText = holder.FocusItem0.GetComponent <Text>(); ComboTitleText.text = TEXT_COMBO_STRING; ComboText = holder.FocusItem1.GetComponent <Text>(); ComboText.text = ""; m_gFillBar = holder.Background; m_gComboObject.SetActive(false); }
// Use this for initialization public void Init() { //Set up Bar GameObjectHolder component = gameObject.GetComponent <GameObjectHolder>(); if (component) { Debug.Log("PlankGame: Init: Component: Found It"); m_iGoalObject = component.FocusItem0; m_iPlankObject = component.FocusItem1; } else { Debug.Log("PlankGame: Init: Failed"); } Reset(); }
private void Start() { handler = GameObject.Find("userData").GetComponent <jsonDataHandler>(); gameMap = gameObject.GetComponent <Graph>(); gameCTRL = gameObject.GetComponent <waveHandler>(); gameData = gameObject.GetComponent <sendDataToForm>(); gameComponents = gameObject.GetComponent <GameObjectHolder>(); money = gameComponents.HealthAndCurrency.GetComponent <currencyCounter>(); fillMapWithPoints(); initializeMapSettings(); if (handler.currentMapIndex == handler.data.maps.Count - 1) { restartOrNewMap.text = "Restart"; } else { restartOrNewMap.text = "Next Map"; } }
private void Start() //In the future this won't be needed { objs = gameObject.GetComponent <GameObjectHolder>(); }
private void LoadModel(int EntryIndex) { if (EntryIndex < 0 || EntryIndex >= Result.ModelsPAK.Models.Count) { Debug.LogWarning("Asked to load model at index " + EntryIndex + ", which is out of bounds!"); //return new GameObject(); return; } alien_pak_model_entry ChunkArray = Result.ModelsPAK.Models[EntryIndex]; for (int ChunkIndex = 0; ChunkIndex < ChunkArray.Header.ChunkCount; ++ChunkIndex) { int BINIndex = ChunkArray.ChunkInfos[ChunkIndex].BINIndex; alien_model_bin_model_info Model = Result.ModelsBIN.Models[BINIndex]; //if (Model.BlockSize == 0) continue; alien_vertex_buffer_format VertexInput = Result.ModelsBIN.VertexBufferFormats[Model.VertexFormatIndex]; alien_vertex_buffer_format VertexInputLowDetail = Result.ModelsBIN.VertexBufferFormats[Model.VertexFormatIndexLowDetail]; BinaryReader Stream = new BinaryReader(new MemoryStream(ChunkArray.Chunks[ChunkIndex])); List <List <alien_vertex_buffer_format_element> > Elements = new List <List <alien_vertex_buffer_format_element> >(); alien_vertex_buffer_format_element ElementHeader = new alien_vertex_buffer_format_element(); foreach (alien_vertex_buffer_format_element Element in VertexInput.Elements) { if (Element.ArrayIndex == 0xFF) { ElementHeader = Element; continue; } while (Elements.Count - 1 < Element.ArrayIndex) { Elements.Add(new List <alien_vertex_buffer_format_element>()); } Elements[Element.ArrayIndex].Add(Element); } Elements.Add(new List <alien_vertex_buffer_format_element>() { ElementHeader }); List <UInt16> InIndices = new List <UInt16>(); List <Vector3> InVertices = new List <Vector3>(); List <Vector3> InNormals = new List <Vector3>(); List <Vector4> InTangents = new List <Vector4>(); List <Vector2> InUVs0 = new List <Vector2>(); List <Vector2> InUVs1 = new List <Vector2>(); List <Vector2> InUVs2 = new List <Vector2>(); List <Vector2> InUVs3 = new List <Vector2>(); List <Vector2> InUVs7 = new List <Vector2>(); //TODO: implement skeleton lookup for the indexes List <Vector4> InBoneIndexes = new List <Vector4>(); //The indexes of 4 bones that affect each vertex List <Vector4> InBoneWeights = new List <Vector4>(); //The weights for each bone for (int VertexArrayIndex = 0; VertexArrayIndex < Elements.Count; ++VertexArrayIndex) { alien_vertex_buffer_format_element Inputs = Elements[VertexArrayIndex][0]; if (Inputs.ArrayIndex == 0xFF) { for (int i = 0; i < Model.IndexCount; i++) { InIndices.Add(Stream.ReadUInt16()); } } else { for (int VertexIndex = 0; VertexIndex < Model.VertexCount; ++VertexIndex) { for (int ElementIndex = 0; ElementIndex < Elements[VertexArrayIndex].Count; ++ElementIndex) { alien_vertex_buffer_format_element Input = Elements[VertexArrayIndex][ElementIndex]; switch (Input.VariableType) { case alien_vertex_input_type.AlienVertexInputType_v3: { Vector3 Value = new Vector3(Stream.ReadSingle(), Stream.ReadSingle(), Stream.ReadSingle()); switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_N: InNormals.Add(Value); break; case alien_vertex_input_slot.AlienVertexInputSlot_T: InTangents.Add(new Vector4(Value.x, Value.y, Value.z, 0)); break; case alien_vertex_input_slot.AlienVertexInputSlot_UV: //TODO: 3D UVW break; } ; break; } case alien_vertex_input_type.AlienVertexInputType_u32_C: { int Value = Stream.ReadInt32(); switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_C: //?? break; } break; } case alien_vertex_input_type.AlienVertexInputType_v4u8_i: { Vector4 Value = new Vector4(Stream.ReadByte(), Stream.ReadByte(), Stream.ReadByte(), Stream.ReadByte()); switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_BI: InBoneIndexes.Add(Value); break; } break; } case alien_vertex_input_type.AlienVertexInputType_v4u8_f: { Vector4 Value = new Vector4(Stream.ReadByte(), Stream.ReadByte(), Stream.ReadByte(), Stream.ReadByte()); Value /= 255.0f; switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_BW: float Sum = Value.x + Value.y + Value.z + Value.w; InBoneWeights.Add(Value / Sum); break; case alien_vertex_input_slot.AlienVertexInputSlot_UV: InUVs2.Add(new Vector2(Value.x, Value.y)); InUVs3.Add(new Vector2(Value.z, Value.w)); break; } break; } case alien_vertex_input_type.AlienVertexInputType_v2s16_UV: { Vector2 Value = new Vector2(Stream.ReadInt16(), Stream.ReadInt16()); Value /= 2048.0f; switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_UV: if (Input.VariantIndex == 0) { InUVs0.Add(Value); } else if (Input.VariantIndex == 1) { // TODO: We can figure this out based on alien_vertex_buffer_format_element. //Material->Material.Flags |= Material_HasTexCoord1; InUVs1.Add(Value); } else if (Input.VariantIndex == 2) { InUVs2.Add(Value); } else if (Input.VariantIndex == 3) { InUVs3.Add(Value); } else if (Input.VariantIndex == 7) { InUVs7.Add(Value); } break; } break; } case alien_vertex_input_type.AlienVertexInputType_v4s16_f: { Vector4 Value = new Vector4(Stream.ReadInt16(), Stream.ReadInt16(), Stream.ReadInt16(), Stream.ReadInt16()); Value /= (float)Int16.MaxValue; switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_P: InVertices.Add(Value); break; } break; } case alien_vertex_input_type.AlienVertexInputType_v4u8_NTB: { Vector4 Value = new Vector4(Stream.ReadByte(), Stream.ReadByte(), Stream.ReadByte(), Stream.ReadByte()); Value /= (float)byte.MaxValue - 0.5f; Value.Normalize(); switch (Input.ShaderSlot) { case alien_vertex_input_slot.AlienVertexInputSlot_N: InNormals.Add(Value); break; case alien_vertex_input_slot.AlienVertexInputSlot_T: break; case alien_vertex_input_slot.AlienVertexInputSlot_B: break; } } break; } } } } CATHODE.Utilities.Align(ref Stream, 16); } if (InVertices.Count == 0) { continue; } Mesh thisMesh = new Mesh(); thisMesh.name = Result.ModelsBIN.ModelFilePaths[BINIndex] + ": " + Result.ModelsBIN.ModelLODPartNames[BINIndex]; thisMesh.SetVertices(InVertices); thisMesh.SetNormals(InNormals); thisMesh.SetIndices(InIndices, MeshTopology.Triangles, 0); //0?? thisMesh.SetTangents(InTangents); thisMesh.SetUVs(0, InUVs0); thisMesh.SetUVs(1, InUVs1); thisMesh.SetUVs(2, InUVs2); thisMesh.SetUVs(3, InUVs3); thisMesh.SetUVs(7, InUVs7); //thisMesh.SetBoneWeights(InBoneWeights.ToArray()); thisMesh.RecalculateBounds(); thisMesh.RecalculateNormals(); thisMesh.RecalculateTangents(); GameObjectHolder ThisModelPart = new GameObjectHolder(); ThisModelPart.LocalScale = new Vector3(Model.ScaleFactor, Model.ScaleFactor, Model.ScaleFactor); ThisModelPart.Name = Result.ModelsBIN.ModelFilePaths[BINIndex] + ": " + Result.ModelsBIN.ModelLODPartNames[BINIndex] + " (" + Result.ModelsMTL.MaterialNames[Model.MaterialLibraryIndex] + ")"; ThisModelPart.MainMesh = thisMesh; ThisModelPart.DefaultMaterial = Model.MaterialLibraryIndex; LoadedModels[BINIndex] = ThisModelPart; } }
// Override: MonoBehaviour::Start void Start() { // Local variables GameObject obj = null; GameObjectHolder holder = null; FSMEventHighjack hj = null; bool triggerAvailable = false; // Trigger collders defined? if (m_triggerColliders == null || m_triggerColliders.Length <= 0) { Debug.LogWarning("No colliders has been defined!"); return; } foreach (Collider c in m_triggerColliders) { if (c.isTrigger == true) { triggerAvailable = true; break; } } if (triggerAvailable == false) { Debug.LogWarning("At least one trigger collider is required!"); return; } // Auto detect player? if (m_autoDetectBilly == true) { obj = GameObject.FindGameObjectWithTag(Tags.TAG_PLAYER); if (obj != null) { // Create holder holder = new GameObjectHolder(); holder.m_targetObject = obj; holder.m_parent = obj.transform.parent.gameObject; m_holders.Add(holder); } } // Add defined target objects to list if (m_targetObjects != null && m_targetObjects.Length > 0) { // Loop through all entries foreach (GameObject g in m_targetObjects) { // Create holder holder = new GameObjectHolder(); holder.m_targetObject = g; holder.m_parent = g.transform.parent.gameObject; m_holders.Add(holder); } // Clear m_targetObjects = null; } if (m_holders.Count <= 0) { Debug.LogWarning("At least one target object is required!"); return; } // Highjack all target objects foreach (GameObjectHolder h in m_holders) { // Inject script hj = h.m_targetObject.AddComponent <FSMEventHighjack>(); hj.FSMOnTriggerEnter += (Collider _other) => { // Detect hit collider foreach (Collider c in m_triggerColliders) { if (_other.gameObject.Equals(c.gameObject) == true) { // Found! Change parent h.m_targetObject.transform.parent = _other.transform; } } }; hj.FSMOnTriggerLeave += (Collider _other) => { // Detect hit collider foreach (Collider c in m_triggerColliders) { if (_other.gameObject.Equals(c.gameObject) == true) { // Found! Change parent to the original one h.m_targetObject.transform.parent = h.m_parent.transform; } } }; } }