protected override void HandleDispose(object additionalData) { slConstants.FoodType foodType = m_IsReaminsFoodContamination ? slConstants.FoodType.Contamination : slConstants.FoodType.Remains; float power = m_IsReaminsFoodContamination ? m_RemainsFoodContaminationPower : m_TweakableProperties.RemainsFoodPower; if (m_AliveState != AliveState.DeadFinishGame) { slWorld.GetInstance().GetFoodSystem().AddCreateEvent(foodType, m_Head.GetPosition(), m_Properties.DeadFoodColor, power); slWorld.GetInstance().GetFoodSystem().AddCreateEvent(foodType, m_Clothes.GetPosition(), m_Properties.DeadFoodColor, power); foreach (BodyNode node in m_Bodys) { slWorld.GetInstance().GetFoodSystem().AddCreateEvent(foodType, node.GetPosition(), m_Properties.DeadFoodColor, power); } } m_SkillEventArgs = null; m_Controller.UnControllerSnake(); m_Controller = null; m_Head.Deactive(); slWorld.GetInstance().GetSnakeSystem().GetHeadPool(m_SnakeName).Push(m_Head); m_Head = null; m_Clothes.Deactive(); slWorld.GetInstance().GetSnakeSystem().GetClothesPool(m_SnakeName).Push(m_Clothes); m_Clothes = null; int bodyCount = m_Bodys.Count; for (int iBody = 0; iBody < bodyCount; iBody++) { BodyNode bodyNode = m_Bodys.PopBack(); bodyNode.Deactive(); m_BodyPool.Push(bodyNode); } m_Bodys.Clear(); m_Bodys = null; Destroy(m_TweakableProperties); m_TweakableProperties = null; Destroy(m_TweakableProperties); m_Properties = null; }
protected override void HandleInitialize(object additionalData) { InitializeAdditionalData initializeData = additionalData as InitializeAdditionalData; hwmDebug.Assert(initializeData.NodeCount >= slConstants.SNAKE_INITIALIZEZ_NODE_MINCOUNT, "initializeData.NodeCount >= slConstants.SNAKE_INITIALIZEZ_NODE_MINCOUNT"); m_AliveState = AliveState.Alive; m_SnakeName = initializeData.SnakeName; m_TweakableProperties = slWorld.GetInstance().GetSnakeSystem().GetTweakableProperties(initializeData.TweakableProperties); m_Properties = slWorld.GetInstance().GetSnakeSystem().GetProperties(m_SnakeName); m_Power = initializeData.NodeCount * m_TweakableProperties.NodeToPower; #region Head m_Head = slWorld.GetInstance().GetSnakeSystem().GetHeadPool(m_SnakeName).Pop(); m_Head.Active(this); m_Head.SetPositionAndRotation(initializeData.HeadPosition, initializeData.HeadRotation); #endregion #region Clothes m_Clothes = slWorld.GetInstance().GetSnakeSystem().GetClothesPool(m_SnakeName).Pop(); m_Clothes.Active(this); m_Clothes.SetPositionAndRotation(initializeData.HeadPosition + initializeData.HeadRotation * new Vector3(0, -slConstants.SNAKE_NODE_TO_NODE_DISTANCE, 0) , initializeData.HeadRotation); #endregion #region Body m_BodyPool = slWorld.GetInstance().GetSnakeSystem().GetBodyPool(m_SnakeName); m_Bodys = new hwmDeque <BodyNode>(16); Vector3 bodyToClothesOffset = initializeData.HeadRotation * new Vector3(0, -slConstants.SNAKE_NODE_TO_NODE_DISTANCE, 0); Vector3 bodyToBodyOffset = initializeData.HeadRotation * new Vector3(0, -slConstants.SNAKE_NODE_TO_NODE_DISTANCE, 0); for (int iNode = 3; iNode <= initializeData.NodeCount; iNode++) // MagicNumber: 1->Head 2->Clothes 3->FirstBody { BodyNode node = m_BodyPool.Pop(); node.Active(this); node.SetPositionAndRotation(m_Clothes.GetPosition() + bodyToClothesOffset + bodyToBodyOffset * (iNode - 3) , initializeData.HeadRotation); if (node.Sprite != null) { node.Sprite.sortingOrder = slConstants.SNAKE_SPRITERENDERER_MIN_ORDERINLAYER + initializeData.NodeCount - iNode; } m_Bodys.PushBack(node); } #endregion if (initializeData.IsBot) { m_Controller = gameObject.AddComponent <slAIController>(); m_Controller.Initialize(); } else { m_Controller = slWorld.GetInstance().GetPlayerController(); } m_Controller.SetControllerSnake(this); TargetMoveDirection = (initializeData.HeadRotation * Vector2.up).normalized; m_CurrentMoveDirection = TargetMoveDirection; m_SpeedState = SpeedState.Normal; m_EnableDamageType = int.MaxValue; m_CanEatFood = true; m_SkillEventArgs = new slSkill.EventArgs(); m_IsReaminsFoodContamination = false; }