コード例 #1
0
        public void AddChild()
        {
            VFXModel modelA = ScriptableObject.CreateInstance <VFXModelA>();
            VFXModel modelB = ScriptableObject.CreateInstance <VFXModelB>();
            VFXModel modelC = ScriptableObject.CreateInstance <VFXModelC>();

            // Test both interfaces
            s_logs.Clear();
            modelA.AddChild(modelB);
            modelC.Attach(modelB);

            Assert.AreEqual(1, modelA.GetNbChildren());
            Assert.AreEqual(modelB, modelA[0]);
            Assert.AreEqual(modelA, modelB.GetParent());

            Assert.AreEqual(1, modelB.GetNbChildren());
            Assert.AreEqual(modelC, modelB[0]);
            Assert.AreEqual(modelB, modelC.GetParent());

            Assert.AreEqual(5, s_logs.Count);
            Assert.AreEqual("OnAdded VFXModelB", s_logs[0]);
            Assert.AreEqual("OnInvalidate VFXModelA kStructureChanged", s_logs[1]);
            Assert.AreEqual("OnAdded VFXModelC", s_logs[2]);
            Assert.AreEqual("OnInvalidate VFXModelB kStructureChanged", s_logs[3]);
            Assert.AreEqual("OnInvalidate VFXModelA kStructureChanged", s_logs[4]);
        }
コード例 #2
0
        public void RemoveChild()
        {
            VFXModel modelA = ScriptableObject.CreateInstance <VFXModelA>();
            VFXModel modelB = ScriptableObject.CreateInstance <VFXModelB>();
            VFXModel modelC = ScriptableObject.CreateInstance <VFXModelC>();

            // First add children but don't notify
            modelB.Attach(modelA, false);
            modelC.Attach(modelB, false);

            // Test both interfaces
            s_logs.Clear();
            modelC.Detach();
            modelA.RemoveChild(modelB);

            Assert.AreEqual(0, modelA.GetNbChildren());
            Assert.IsNull(modelB.GetParent());

            Assert.AreEqual(0, modelB.GetNbChildren());
            Assert.IsNull(modelC.GetParent());

            Assert.AreEqual(5, s_logs.Count);
            Assert.AreEqual("OnRemoved VFXModelC", s_logs[0]);
            Assert.AreEqual("OnInvalidate VFXModelB kStructureChanged", s_logs[1]);
            Assert.AreEqual("OnInvalidate VFXModelA kStructureChanged", s_logs[2]);
            Assert.AreEqual("OnRemoved VFXModelB", s_logs[3]);
            Assert.AreEqual("OnInvalidate VFXModelA kStructureChanged", s_logs[4]);
        }