static public void SetPhysInterpolation(GameObject body, bool interpolate) { if (GlobalSettings.renderingBodyAndBones && interpolate) { body.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; } else { body.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.None; } DragonScript scr = body.gameObject.GetComponent <DragonScript>(); foreach (Rigidbody obj in scr.wingSet.segments) { if (obj != null) { if (GlobalSettings.renderingBodyAndBones && interpolate) { obj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; } else { obj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.None; } } } }
public static void EvaluateSample(GameObject body, DragonScript scr, float wingSurface, float[] performanceOfChromosomes) { EvaluatedPhenotype evaluationData = new EvaluatedPhenotype(scr.wingSet.phenotype, body.transform.position.y, wingSurface, performanceOfChromosomes); evaluationData.AddToList(evaluatedPhenotypesGood, evaluatedPhenotypesBad); RemoveSample(body, scr); }
static public void DestroyWing(GameObject body) { DragonScript scr = body.GetComponent <DragonScript>(); activeWings.Remove(scr.wingSet); scr.wingSet.Destroy(); scr.wingSet = null; }
// Use this for initialization void Start() { dragonTransform = (Transform)this.GetComponent(typeof(Transform)); dragonRenderer = (Renderer)this.GetComponent <Renderer>(); dragonBody = (Rigidbody)this.GetComponent(typeof(Rigidbody)); dragonScr = (DragonScript)this.GetComponent(typeof(DragonScript)); inAITest = (Global.GetCurrentScene() == Global.mainAIScene); }
public static void RemoveSample(GameObject body, DragonScript scr) { freeIndices.Add(scr.index); population.Remove(body); Destroy(body); testedSamples++; Global.AIControlerScr.GeneratePhenotypes(readyPhenotypes, freeIndices); AddPossibleSamples(); }
// Turns the population into readyPhenotypes to "save" them when the have to be destroyed for switching into TestMode. public static void SaveAndDestroyPopulation() { freeIndices.Clear(); for (int i = 0; i < population.Count; i++) { DragonScript scr = population[i].GetComponent <DragonScript>(); readyPhenotypes.Add(scr.wingSet.phenotype); Destroy(population[i]); freeIndices.Add(i); } population.Clear(); }
// Use the prefab to instantiate an actual body of the sample (the block at the middle) static public GameObject CreateDragon(Phenotype type, Vector3 startPosition, Quaternion startRotation, int index) { // Create new body GameObject body = (GameObject)Instantiate(DragonBody, startPosition, startRotation); DragonScript scr = body.gameObject.GetComponent <DragonScript>(); scr.index = index; // Create and atatch a wing AttachWing(body, type); return(body); }
private void renderDragons() { foreach (Dragon d in currentRoom.dragons) { GameObject obj; if (d is Dragon) { obj = Instantiate(dragonPrefab); DragonScript cs = obj.GetComponent <DragonScript>(); cs.myDragon = d; cs.main = this; roomStuff.Add(obj); } } }
// Renderings etting function for a certain object static public void SetBodyAndBonesRendering(GameObject body, bool render) { // Set render for main body body.GetComponent <Renderer>().enabled = render; body.GetComponent <MeshRenderer>().enabled = render; // Set render for wing bones DragonScript scr = body.gameObject.GetComponent <DragonScript>(); foreach (Rigidbody obj in scr.wingSet.segments) { if (obj != null) { if (render && GlobalSettings.physInterpolate) { obj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.Interpolate; } else { obj.GetComponent <Rigidbody>().interpolation = RigidbodyInterpolation.None; } obj.GetComponent <Renderer>().enabled = render; obj.GetComponent <MeshRenderer>().enabled = render; } } // Attach DragonVisualisation Script if (render) { if (body.GetComponent <DragonVisualisation>() == null) { body.AddComponent <DragonVisualisation>(); } } else if (body.GetComponent <DragonVisualisation>() != null) { Destroy(body.GetComponent <DragonVisualisation>()); } }
public void Start () { // initialize tables EventReader.GetInstance(); ReactionReader.GetInstance(); SequenceReader.GetInstance(); AffectedActionReader.GetInstance(); MoodPointsReader.GetInstance(); ReactionTrackingReader.GetInstance(); TutorialReader.GetInstance(); ResponseManager.Instance.HideIcon(); InstructionsManager.Instance.HideInstruction(); // hold instance m_instance = this; //Load intro rocks m_introRock = Instantiate( Resources.Load( "AnimationTool/INTRO_ROCK" ) ) as GameObject; m_introRock.SetActive( false ); // init anim controller utility GameObject cfController = GameObject.Find("CAREPLAY_NF_Controller") as GameObject; cfController.AddComponent<CarePlayNFController>(); cfController.AddComponent<BiteItemController>(); // init cam controller utility m_cameraController = GameObject.Find ("CAREPLAY_Cam_Controller").GetComponent<CameraRigController>(); // init dragon m_petDragon = GameObject.FindGameObjectWithTag("PetDragon") as GameObject; m_petDragon.gameObject.AddComponent<DragonScript>(); m_petDragon.gameObject.AddComponent<DragonAnimation>(); m_petDragon.gameObject.AddComponent<Dragon>(); m_petDragon.gameObject.AddComponent<JawCruncherStateController>(); m_jcController = m_petDragon.gameObject.GetComponent<JawCruncherStateController>(); // init gestures m_mainCamera = GameObject.FindGameObjectWithTag("MainCamera").gameObject; m_mainCamera.AddComponent<GestureManager>(); m_gestureManager = Camera.mainCamera.gameObject.GetComponent<GestureManager>(); m_gestureManager.g_pettingListener = this.GestureListener; m_gestureManager.SetPettingDelegate(this); CameraController.Instance.SetPettingDelegate(this); //m_gestureManager.DisableGestures(); // init bridge items m_sheepManager = GameObject.Find("SheepManager").GetComponent<SheepManager>(); m_sheepManager.InitializeSheep(); // init dragon collider GameObject HeadCollider = (GameObject)Resources.Load("Prefabs/Petting/DragonColliders/HeadCollider"); GameObject BodyCollider = (GameObject)Resources.Load("Prefabs/Petting/DragonColliders/BodyCollider"); m_dragonHeadCollider = GameObject.Instantiate(HeadCollider) as GameObject; m_dragonBodyCollider = GameObject.Instantiate(BodyCollider) as GameObject; m_dragonHeadCollider.transform.parent = m_petDragon.transform.Find("joint_Spine/joint_Neck/joint_Head").transform; m_dragonHeadCollider.name = "HeadCollider"; m_dragonHeadCollider.transform.localPosition = new Vector3(-0.00785967f, -0.03883493f, 0.2275544f); m_dragonHeadCollider.transform.localRotation = Quaternion.Euler(new Vector3(335.4119f, 184.195f, 1.887401f)); m_dragonHeadCollider.transform.localScale = new Vector3(0.6969064f, 0.4911779f, 1.063113f); m_dragonBodyCollider.transform.parent = m_petDragon.transform.Find("joint_Spine").transform; m_dragonBodyCollider.name = "BodyCollider"; m_dragonBodyCollider.transform.localPosition = new Vector3(0.0176101f, -0.2866409f, -0.8635432f); m_dragonBodyCollider.transform.localRotation = Quaternion.Euler(new Vector3(270.0f, 180.0f, 0.0f)); //m_dragonBodyCollider.transform.localScale = new Vector3(1.043613f, 1.421112f, 1.043613f); //init camera focus point m_cameraFocusPoint = new GameObject ( "FocusPoint" ); m_cameraFocusPoint.tag = "ToothlessFocusPoint"; GameObject toothlessAxis = GameObject.Find("joint_Spine"); m_cameraFocusPoint.transform.parent = toothlessAxis.transform; m_cameraFocusPoint.transform.position = toothlessAxis.transform.position; m_cameraFocusPoint.transform.rotation = Quaternion.identity; //Sound audio source container m_headSoundContainer = new GameObject( "SoundContainer_Head" ); m_headSoundContainer.transform.parent = toothlessAxis.transform; m_headSoundContainer.transform.position = toothlessAxis.transform.position; m_headSoundContainer.transform.rotation = Quaternion.identity; m_bodySoundContainer = new GameObject( "SoundContainer_Body" ); m_bodySoundContainer.transform.parent = toothlessAxis.transform; m_bodySoundContainer.transform.position = toothlessAxis.transform.position; m_bodySoundContainer.transform.rotation = Quaternion.identity; m_headAndBodySoundContainer = new GameObject( "SoundContainer_HeadAndBody" ); m_headAndBodySoundContainer.transform.parent = toothlessAxis.transform; m_headAndBodySoundContainer.transform.position = toothlessAxis.transform.position; m_headAndBodySoundContainer.transform.rotation = Quaternion.identity; // Camera Look Points GameObject cHead = new GameObject( "CamPlayerHead" ); GameObject cBody = new GameObject( "CamPlayerBody" ); GameObject cLeft = new GameObject( "CamPlayerLeft" ); GameObject cRight = new GameObject( "CamPlayerRight" ); cHead.tag = "CamPlayerHead"; cBody.tag = "CamPlayerBody"; cLeft.tag = "CamPlayerLeft"; cRight.tag = "CamPlayerRight"; cHead.transform.parent = m_mainCamera.gameObject.transform; cBody.transform.parent = m_mainCamera.gameObject.transform; cLeft.transform.parent = m_mainCamera.gameObject.transform; cRight.transform.parent = m_mainCamera.gameObject.transform; cHead.transform.localPosition = new Vector3( 0.0f, 0.30f, 0.0f ); cBody.transform.localPosition = new Vector3( 0.0f, -0.30f, 0.0f ); cLeft.transform.localPosition = new Vector3( -1.2f, 0.0f, 0.0f ); cRight.transform.localPosition = new Vector3( 1.2f, 0.0f, 0.0f ); cHead.transform.localScale = new Vector3( 0.001f, 0.001f, 0.001f ); cBody.transform.localScale = new Vector3( 0.001f, 0.001f, 0.001f ); cLeft.transform.localScale = new Vector3( 0.001f, 0.001f, 0.001f ); cRight.transform.localScale = new Vector3( 0.001f, 0.001f, 0.001f ); // Dragon Look Points GameObject lookL = new GameObject( "DLookL" ); GameObject lookR = new GameObject( "DLookR" ); lookL.tag = "DLookL"; lookR.tag = "DLookR"; lookL.transform.parent = m_petDragon.transform; lookL.transform.position = new Vector3( 3.50f, 2.00f, -1.00f ); lookR.transform.parent = m_petDragon.transform; lookR.transform.position = new Vector3( -3.50f, 2.00f, -1.00f ); // init ui m_uiRefs = new Hashtable(); m_carePlayUI = GameObject.Find("CareAndPlayHUD") as GameObject; m_carePlayUI.GetComponent<CareAndPlayHUD>(); m_carePlayUI.GetComponent<GamePauseManager>().PauseCallBack = this.PauseGame; m_carePlayTab = GameObject.Find("MainTab") as GameObject; m_uiManager = m_carePlayUI.AddComponent<CarePlayUIManager>(); m_uiManager.Initialize(); m_uiManager.SetCB_Call(this.OnDragonCall); m_uiManager.SetCB_Book(this.OnBookOfDragon); m_uiManager.SetCB_Inventory(this.OnInventory); m_uiManager.SetCB_Inventory_Close(this.OnInventoryClose); m_uiManager.SetCB_Map(this.OnMap); m_uiManager.SetCB_Profile(this.OnProfile); m_uiManager.SetCB_Profile_Close(this.OnProfileClose); m_tabManager = m_carePlayTab.GetComponent<CarePlayTabManager>(); m_energyGauge = GameObject.Find("EnergyProgress") as GameObject; m_bondGauge = GameObject.Find("BondProgress") as GameObject; m_energyBondUI = GameObject.Find("EnergyBond") as GameObject; m_pauseUI = GameObject.Find("PauseBTN") as GameObject; StatsManager.Instance.EnergyGauge = m_energyGauge.GetComponent<EnergyProgress>(); StatsManager.Instance.BondGauge = m_bondGauge.GetComponent<BondProgress>(); // UI finger tap m_uiFingerSingleTap = GameObject.Find("SingleTapFinger") as GameObject; m_uiFingerDoubleTap = GameObject.Find("DoubleTapFinger") as GameObject; m_uiFingerHold = GameObject.Find("HoldFinger") as GameObject; m_uiFingerSingleTap.transform.parent.localPosition = new Vector3( -6.043911e-05f, 319.0215f, 0f ); m_uiFingerSingleTap.SetActive(false); m_uiFingerDoubleTap.SetActive(false); m_uiFingerHold.SetActive(false); // set inventory callbacks InventoryUIHandler.OnFeedingItemCallback = this.OnFeedingItem; InventoryUIHandler.OnFetchingItemCallback = this.OnFetchingItem; InventoryUIHandler.OnCarePlayItemCallback = this.OnCarePlayItem; // set Hud Callback to enable gestures //m_carePlayUI.GetComponent<CareAndPlayHUD>().SetDialogCloseCB(m_gestureManager.EnableGestures); // init dragon animation controller m_dragonAnimScript = m_petDragon.gameObject.GetComponent<DragonScript>(); m_dragonAnimScript.SetPettingDelegate(this); // init dragon animation m_dragonAnimation = m_petDragon.gameObject.GetComponent<DragonAnimation>(); m_dragonAnimation.SetPettingDelegate(this); m_petDragon.GetComponent<JawCruncherStateController>().SetPettingDelegate( this ); // init dragon animation tool DragonAnimationQueue.getInstance().SetDAnim(m_petDragon.gameObject.GetComponent<DragonAnimation>()); DragonAnimationQueue.getInstance().SetPettingDelegate(this); // initialize DragonStateMachine m_dragonStateMachine = m_petDragon.gameObject.GetComponent<Dragon>(); m_dragonStateMachine.SetPettingDelegate(this); m_dragonStateMachine.Initialize(); // initialize DragonScript m_dragonAnimScript.Initialize(); // Setup Pausables m_petDragon.AddComponent<Pausable>(); m_mainCamera.AddComponent<Pausable>(); // reset values StatsManager.Instance.DragonMode = StatsManager.MODE_NORMAL; // - LA //StatsManager.Instance.DragonMode = StatsManager.MODE_ACT1; // - LA // on start of touchplay, always set interactive to true m_dragonStateMachine.SetIsInteractible(true); // Swipe UI m_swipeUI = GameObject.Find("SwipeUI"); m_swipeHolder = GameObject.Find("SwipeHolder"); m_swipeFingerGO = GameObject.Find("SwipeFinger"); m_swipeFinger = m_swipeFingerGO.GetComponent<TweenPosition>(); m_swipeUITexture = m_swipeUI.GetComponent<UITexture>(); m_swipeUITexture.alpha = 0.3f; m_swipeHolder.SetActive(false); m_swipeUI.GetComponent<UITexture>().alpha = 0.5f; m_swipeFingerGO.GetComponent<UITexture>().alpha = 0.75f; //Double Tap UI m_doubleTapTweenPos = GameObject.Find("DoubleTapUI").GetComponent<TweenPosition>(); GameObject successIcon = GameObject.Find("SuccesIcon"); UISprite spriteSucccessIcon = successIcon.GetComponent<UISprite>(); spriteSucccessIcon.alpha = 0.0f; m_successIconTweenAlpha = successIcon.GetComponent<TweenAlpha>(); m_successIconTweenAlpha.onFinished=ResetSuccesAnimation; // hide UIs this.HideUI("DCall"); // Handle Timer for Usage Tracker m_usageTrackerScheduler = S6Scheduler.ScheduleAction( this, StatsManager.Instance.UpdateTrackers, 0.5f, S6Scheduler.INFINITE, false); // update dragon mood for Animation Controllers StatsManager.Instance.UpdateMood(); // load objects // fish m_fishItems.Add(this.CreateObject( "Fish", "Prefabs/Feeding/FeedingFish", 1.0f)); // chicken m_chickenItems.Add(this.CreateObject( "ChickenLeg", "Prefabs/Feeding/FeedingChickenLeg", 1.0f)); m_chickenItems.Add(this.CreateObject( "ChickenThigh", "Prefabs/Feeding/FeedingChickenThigh", 1.0f)); m_chickenItems.Add(this.CreateObject( "ChickenWing", "Prefabs/Feeding/FeedingChickenWing", 1.0f)); // seafood m_seafoodItems.Add(this.CreateObject( "Crab", "Prefabs/Feeding/FeedingCrab", 1.0f)); m_seafoodItems.Add(this.CreateObject( "Lobster", "Prefabs/Feeding/FeedingLobster", 1.0f)); m_seafoodItems.Add(this.CreateObject( "Shrimp", "Prefabs/Feeding/FeedingShrimp", 1.0f)); // fruits & veggies m_fruitsAndVeggiesItems.Add(this.CreateObject( "FruitsAndVeggies", "Prefabs/Feeding/FeedingOrange", 1.0f)); m_fruitsAndVeggiesItems.Add(this.CreateObject( "FruitsAndVeggies", "Prefabs/Feeding/FeedingPeach", 1.0f)); m_fruitsAndVeggiesItems.Add(this.CreateObject( "FruitsAndVeggies", "Prefabs/Feeding/FeedingTurnip", 1.0f)); // fetching items m_fetchingItems.Add(this.CreateObject( "Boomerang", "Prefabs/Fetching/Boomerang", 1.0f)); // adjust boomerang transform m_fetchingItems[0].transform.parent = Camera.main.transform; m_fetchingItems[0].transform.localPosition = new Vector3( -0.05178565f, -0.51644f, 1.536007f ); m_fetchingItems[0].transform.localRotation = Quaternion.Euler(new Vector3( 0.0f, 283.0f, 69.99999f )); // Handle disable/enable of gestures during hide/show of overlays // These methods are called during the initial add & remove of overlays. ScreenManager.Instance.OnDisplayOverlay = () => { switch( TutorialController.GTutState ) { case TutorialController.ETutorialState.BondMeterIntro: case TutorialController.ETutorialState.PlayerProfileIntro: // don't update gestures during this state of tutorial break; default: m_gestureManager.DisableGestures(); break; } }; ScreenManager.Instance.OnHideOverlay = () => { switch( TutorialController.GTutState ) { case TutorialController.ETutorialState.BondMeterIntro: case TutorialController.ETutorialState.PlayerProfileIntro: // don't update gestures during this state of tutorial break; default: m_gestureManager.EnableGestures(); break; } }; // Check Scenes this.HandleScenes(); }
void Awake() { instance = this; }
public void ChangeTaskMode(string mode) { GlobalSettings.taskMode = mode; switch (mode) { case "Learning": Debug.Log("Learning Mode"); // Destroy the full dragon and recreate population if (inLearningMode == false) { Destroy(completeDragon); Destroy(bestSample.gameObject); completeDragon = null; bestSample = null; PopulationControler.AddPossibleSamples(); GlobalSettings.SetBodyAndBonesRendering(renderPhTemp); GlobalSettings.SetMembraneRendering(renderMemTemp); ResizeFloorsFitToPopulation(); } renderPhTemp = GlobalSettings.renderingBodyAndBones; renderMemTemp = GlobalSettings.renderingMembranes; inLearningMode = true; if (bestSample == null) { Global.mainCameraScr.GotoWatchObject(PopulationControler.population[0]); } else { Global.mainCameraScr.GotoWatchObject(bestSample); } Global.mainCameraScr.GotoWatchObjectDistance(35 + Mathf.Sqrt(GlobalSettings.populationSize) * 35); testSampleScript = null; break; case "Testing": if (completeDragon != null) { return; } Debug.Log("Testing Mode"); renderPhTemp = GlobalSettings.renderingBodyAndBones; renderMemTemp = GlobalSettings.renderingMembranes; // Enable rendering of the new phenotype GlobalSettings.SetBodyAndBonesRendering(true); GlobalSettings.SetMembraneRendering(true); // // Save the current population for future use PopulationControler.SaveAndDestroyPopulation(); // Copy the phenotype of the best dragon Phenotype bestPhenotype; if (bestSample == null) { bestPhenotype = PopulationControler.GetBestPhenotype(); } else { bestPhenotype = bestSample.GetComponent <DragonScript>().wingSet.phenotype; } if (bestPhenotype == null) { bestPhenotype = PhenotypeFactory.CreateRandom(); } bestPhenotype.SetDependantBonethickness(0.6f, 0.1f); // Sets bone thicknes depending on the distance from the origin bestPhenotype.SetDependantBonecolor(new Color(0.3f, 1, 0.3f), new Color(0.25f, 0.25f, 1)); // Sets bone color depending on the distance from the origin bestSample = DragonFactory.CreateDragon(bestPhenotype, GlobalSettings.originPoint, Quaternion.Euler(20, 0, 0), 0); // // Calculate optimal gravity for floating float curMax; if (Global.GUIControlerScr.sampleToObserve != null) { curMax = Mathf.Max(bestSampleHeight, Global.GUIControlerScr.sampleVisScriptToObserve.localBestHeight); } else { curMax = bestSampleHeight; } customGravityOnBestSample = new Vector3(0, -(curMax / (bestPhenotype.maxFlapSteps * (GlobalSettings.requiredEvaluationFlaps + 0.5f))) * 75, 0); // ResizeFloors(1); inLearningMode = false; // Make everything visible GlobalSettings.SetBodyAndBonesRendering(bestSample, true); // Make body invisible (leaves wings visible) bestSample.gameObject.GetComponent <MeshRenderer>().enabled = false; // Set interpolation GlobalSettings.SetPhysInterpolation(bestSample, true); // Reenable membrane testSampleScript = bestSample.GetComponent <DragonScript>(); testSampleScript.wingSet.RenderVisualisation(true); Global.mainCameraScr.GotoWatchObject(bestSample); floorOfBest.transform.position = bestSample.transform.position; Global.GUIControlerScr.SwitchObjectToObserve(bestSample); justMovedToWatchNew = true; Global.mainCameraScr.GotoWatchObjectDistance(70); // Create the new surrounding full dragon model completeDragon = (GameObject)Instantiate(CompleteDragonModel, bestSample.transform.position, bestSample.transform.rotation); completeDragon.GetComponent <DragonControler>().followerObject = bestSample; break; } }
private void Awake() { instance = this; }